util

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2022 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const ScheduleIcal = `` /* 415-byte string literal not displayed */

Example for Schedule in ical format

Variables

View Source
var AliasFields = map[string]string{
	"location":       "location_id",
	"p_location":     "p_location_id",
	"d_location":     "d_location_id",
	"start_location": "start_id",
	"end_location":   "end_id",
}
View Source
var IntervalFields = map[string]bool{
	"setup":        true,
	"service":      true,
	"p_setup":      true,
	"p_service":    true,
	"d_setup":      true,
	"d_service":    true,
	"travel_time":  true,
	"setup_time":   true,
	"service_time": true,
	"waiting_time": true,
	"max_shift":    true,
	"timeout":      true,
}
View Source
var TimestampFields = map[string]bool{
	"tw_open":    true,
	"tw_close":   true,
	"arrival":    true,
	"departure":  true,
	"created_at": true,
	"updated_at": true,
}

Functions

func Get added in v0.2.0

func Get(url string, contentType string, target interface{}) (int, error)

make get request to an url with content-type, and return the response body as json

func GetCoordinates

func GetCoordinates(id int64) (latitude float64, longitude float64)

func GetEuclideanMatrix added in v0.2.0

func GetEuclideanMatrix(coordinates [][]float64) ([][]int64, error)

func GetFormattedInterval added in v0.2.0

func GetFormattedInterval(fieldName string) string

func GetFormattedTimestamp added in v0.2.0

func GetFormattedTimestamp(fieldName string) string

func GetLocationId added in v0.2.0

func GetLocationId(latitude float64, longitude float64) int64

func GetMatrix added in v0.2.0

func GetMatrix(locationIds []int64, durationCalc string) (startIds []int64, endIds []int64, durations []int64, err error)

func GetMatrixFromOSRM added in v0.2.0

func GetMatrixFromOSRM(coordinates [][]float64, baseUrl string) ([][]int64, error)

func GetMatrixFromValhalla added in v0.2.0

func GetMatrixFromValhalla(coordinates [][]float64, baseUrl string) ([][]int64, error)

func GetOutputFields

func GetOutputFields(resourceStruct interface{}, tableName string) (sql string)

func GetShipmentTimeWindows added in v0.2.0

func GetShipmentTimeWindows(kind []*string, timeWindows [][]*string) ([][]string, [][]string)

func GetTimeWindows added in v0.2.0

func GetTimeWindows(timeWindows [][]*string) [][]string

func HandleDBError

func HandleDBError(err error) error

func Logger

func Logger(h http.Handler) http.Handler

func NewValidator

func NewValidator() *validator.Validate

func SerializeICal

func SerializeICal(calendar []ICal) string

func ValidateInput

func ValidateInput(jsonStruct map[string]interface{}, originalStruct interface{}) error

Verify that the type of input user struct is same as the required type

Types

type ErrorResponse added in v0.2.0

type ErrorResponse struct {
	Errors  interface{} `json:"errors" swaggertype:"array,string" example:"Error message1,Error message2"`
	Message string      `json:"message" example:"Bad Request"`
	Code    string      `json:"code" example:"400"`
}

type Formatter

type Formatter struct {
	// contains filtered or unexported fields
}

func NewFormatter

func NewFormatter() *Formatter

func (*Formatter) FormatICAL

func (r *Formatter) FormatICAL(w http.ResponseWriter, respCode int, calendar []ICal, filename string)

func (*Formatter) FormatJSON

func (r *Formatter) FormatJSON(w http.ResponseWriter, respCode int, data interface{})

func (*Formatter) GetScheduleICal

func (r *Formatter) GetScheduleICal(scheduleData ScheduleData) ([]ICal, string)

type ICal

type ICal struct {
	ID          string
	CreatedTime time.Time
	DtStampTime time.Time
	ModifiedAt  time.Time
	StartAt     time.Time
	EndAt       time.Time
	Summary     string
	Location    string
	Description string
}

type LocationParams

type LocationParams struct {
	Latitude  *float64 `json:"latitude"  validate:"required,max=90,min=-90" example:"2.0365"`
	Longitude *float64 `json:"longitude" validate:"required,max=180,min=-180" example:"48.6113"`
}

type MetadataResponse added in v0.2.0

type MetadataResponse struct {
	Summary      []ScheduleSummary    `json:"summary"`
	Unassigned   []ScheduleUnassigned `json:"unassigned"`
	TotalTravel  string               `json:"total_travel" example:"01:00:00"`
	TotalSetup   string               `json:"total_setup" example:"00:05:00"`
	TotalService string               `json:"total_service" example:"00:10:00"`
	TotalWaiting string               `json:"total_waiting" example:"00:30:00"`
}

type NotFound

type NotFound struct {
	Error string `json:"error" example:"Not Found"`
	Code  string `json:"code" example:"404"`
}

type PartialSQL

type PartialSQL struct {
	Fields []string
	Args   []interface{}
}

func GetPartialSQL

func GetPartialSQL(resource interface{}) PartialSQL

Get an SQL query with partial fields Takes a resource object as parameter, and returns its fields and arguments. (returns only those arguments which are not nil) See https://stackoverflow.com/questions/38206479/golang-rest-patch-and-building-an-update-query

type ScheduleDB added in v0.2.0

type ScheduleDB struct {
	Type        string         `json:"type" example:"job"`
	ProjectID   int64          `json:"project_id,string" example:"1234567812345678"`
	VehicleID   int64          `json:"vehicle_id,string" example:"1234567812345678"`
	TaskID      int64          `json:"task_id,string" example:"1234567812345678"`
	Location    LocationParams `json:"location"`
	Arrival     string         `json:"arrival" example:"2021-12-01T13:00:00"`
	Departure   string         `json:"departure" example:"2021-12-01T13:00:00"`
	TravelTime  string         `json:"travel_time" example:"00:16:40"`
	SetupTime   string         `json:"setup_time" example:"00:00:00"`
	ServiceTime string         `json:"service_time" example:"00:02:00"`
	WaitingTime string         `json:"waiting_time" example:"00:00:00"`
	Load        []int64        `json:"load" example:"0,0"`
	VehicleData interface{}    `json:"vehicle_data" swaggertype:"object,string" example:"key1:value1,key2:value2"`
	TaskData    interface{}    `json:"task_data" swaggertype:"object,string" example:"key1:value1,key2:value2"`
	CreatedAt   string         `json:"created_at" example:"2021-12-01T13:00:00"`
	UpdatedAt   string         `json:"updated_at" example:"2021-12-01T13:00:00"`
}

type ScheduleData added in v0.2.0

type ScheduleData struct {
	Schedule  []ScheduleResponse `json:"schedule"`
	Metadata  MetadataResponse   `json:"metadata"`
	ProjectID int64              `json:"project_id,string,omitempty" example:"1234567812345678"`
}

type ScheduleDataOverview added in v0.2.0

type ScheduleDataOverview struct {
	Metadata  MetadataResponse `json:"metadata"`
	ProjectID int64            `json:"project_id,string,omitempty" example:"1234567812345678"`
}

type ScheduleDataTask added in v0.2.0

type ScheduleDataTask struct {
	Schedule  []ScheduleResponse `json:"schedule"`
	ProjectID int64              `json:"project_id,string,omitempty" example:"1234567812345678"`
}

type ScheduleResponse added in v0.2.0

type ScheduleResponse struct {
	VehicleID   int64           `json:"vehicle_id,string"`
	VehicleData interface{}     `json:"vehicle_data" swaggertype:"object,string" example:"key1:value1,key2:value2"`
	Route       []ScheduleRoute `json:"route"`
}

type ScheduleRoute added in v0.2.0

type ScheduleRoute struct {
	Type        string         `json:"type" example:"job"`
	TaskID      int64          `json:"task_id,string" example:"1234567812345678"`
	Location    LocationParams `json:"location"`
	Arrival     string         `json:"arrival" example:"2021-12-01T13:00:00"`
	Departure   string         `json:"departure" example:"2021-12-01T13:00:00"`
	TravelTime  string         `json:"travel_time" example:"00:16:40"`
	SetupTime   string         `json:"setup_time" example:"00:00:00"`
	ServiceTime string         `json:"service_time" example:"00:02:00"`
	WaitingTime string         `json:"waiting_time" example:"00:00:00"`
	Load        []int64        `json:"load" example:"0,0"`
	TaskData    interface{}    `json:"task_data" swaggertype:"object,string" example:"key1:value1,key2:value2"`
	CreatedAt   string         `json:"created_at" example:"2021-12-01T13:00:00"`
	UpdatedAt   string         `json:"updated_at" example:"2021-12-01T13:00:00"`
}

type ScheduleSummary added in v0.2.0

type ScheduleSummary struct {
	VehicleID   int64       `json:"vehicle_id,string" example:"1234567812345678"`
	TravelTime  string      `json:"travel_time" example:"00:16:40"`
	SetupTime   string      `json:"setup_time" example:"00:00:00"`
	ServiceTime string      `json:"service_time" example:"00:02:00"`
	WaitingTime string      `json:"waiting_time" example:"00:00:00"`
	VehicleData interface{} `json:"vehicle_data" swaggertype:"object,string" example:"key1:value1,key2:value2"`
}

type ScheduleUnassigned added in v0.2.0

type ScheduleUnassigned struct {
	Type     string         `json:"type" example:"job"`
	TaskID   int64          `json:"task_id,string" example:"1234567812345678"`
	Location LocationParams `json:"location"`
	TaskData interface{}    `json:"task_data" swaggertype:"object,string" example:"key1:value1,key2:value2"`
}

type StatusRespWr

type StatusRespWr struct {
	http.ResponseWriter // We embed http.ResponseWriter
	// contains filtered or unexported fields
}

func (*StatusRespWr) WriteHeader

func (w *StatusRespWr) WriteHeader(status int)

type Success

type Success struct {
	Message string `json:"message" example:"OK"`
	Code    string `json:"code" example:"200"`
}

type SuccessResponse added in v0.2.0

type SuccessResponse struct {
	Data    interface{} `json:"data"`
	Message string      `json:"message" example:"OK"`
	Code    string      `json:"code" example:"200"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL