Documentation ¶
Index ¶
- Constants
- Variables
- func CharAt(str string, index int) string
- func GetApiKey(pzserver string) (string, error)
- func GetApiServer() (string, error)
- func GetBasicAuthHeader(username, password string) [2]string
- func GetExternalIP() (string, error)
- func GetPiazzaServiceUrl(serviceName ServiceName) (string, error)
- func GetPiazzaUrl() (string, error)
- func GetValueFromHeader(header http.Header, field string) string
- func GetVarsFromStruct(struc interface{}) (map[string]interface{}, error)
- func GetVarsFromStructSkip(struc interface{}, skipMaps map[string]bool) (map[string]interface{}, error)
- func GinReturnJson(c *gin.Context, resp *JsonResponse)
- func HTTP(requestType, url string, headers [][2]string, toSend io.Reader) (int, []byte, http.Header, error)
- func HTTPDelete(url string) (*http.Response, error)
- func HTTPPut(url string, contentType string, body io.Reader) (*http.Response, error)
- func InsertString(str, insert string, index int) string
- func RemoveWhitespace(str string) string
- func RequestAuthZAccess(idamURL string, actor string) (authorized bool, err error)
- func SplitString(str string, whereToSplit int) (string, string)
- func StructInterfaceToString(stru interface{}) (string, error)
- func StructStringToInterface(stru string) (interface{}, error)
- func UnmarshalNumber(r io.Reader, v interface{}) error
- func ValidUuid(uuid string) bool
- func ValueIsValidArray(value interface{}) bool
- func WaitForService(name ServiceName, url string) error
- func WaitForServiceToDie(name ServiceName, url string) error
- type FlightCheck
- type GenericServer
- type HeaderBuilder
- type Http
- func (h *Http) Delete(endpoint string, output interface{}) (int, error)
- func (h *Http) Get(endpoint string, output interface{}) (int, error)
- func (h *Http) Get2(endpoint string, input interface{}, output interface{}) (int, error)
- func (h *Http) Post(endpoint string, input interface{}, output interface{}) (int, error)
- func (h *Http) Put(endpoint string, input interface{}, output interface{}) (int, error)
- func (h *Http) PzDelete(endpoint string) *JsonResponse
- func (h *Http) PzGet(endpoint string) *JsonResponse
- func (h *Http) PzGet2(endpoint string, input interface{}) *JsonResponse
- func (h *Http) PzPost(endpoint string, input interface{}) *JsonResponse
- func (h *Http) PzPut(endpoint string, input interface{}) *JsonResponse
- func (h *Http) Verb(verb string, endpoint string, input interface{}, output interface{}) (int, error)
- type HttpQueryParams
- func (params *HttpQueryParams) AddString(key string, value string)
- func (params *HttpQueryParams) AddTime(key string, value time.Time)
- func (params *HttpQueryParams) GetAfter(defalt time.Time) (time.Time, error)
- func (params *HttpQueryParams) GetAsID(key string, defalt string) (Ident, error)
- func (params *HttpQueryParams) GetAsInt(key string, defalt int) (int, error)
- func (params *HttpQueryParams) GetAsSortOrder(key string, defalt SortOrder) (SortOrder, error)
- func (params *HttpQueryParams) GetAsString(key string, defalt string) (string, error)
- func (params *HttpQueryParams) GetAsTime(key string, defalt time.Time) (time.Time, error)
- func (params *HttpQueryParams) GetBefore(defalt time.Time) (time.Time, error)
- func (params *HttpQueryParams) GetCount(defalt int) (int, error)
- func (params *HttpQueryParams) GetPage(defalt int) (int, error)
- func (params *HttpQueryParams) GetPerPage(defalt int) (int, error)
- func (params *HttpQueryParams) GetSortBy(defalt string) (string, error)
- func (params *HttpQueryParams) GetSortOrder(defalt SortOrder) (SortOrder, error)
- func (params *HttpQueryParams) String() string
- type Ident
- type JsonPagination
- type JsonResponse
- type JsonString
- type RouteData
- type ServiceName
- type ServicesMap
- type SimpleFlightCheck
- type SortOrder
- type SystemConfig
- func (sys *SystemConfig) AddService(name ServiceName, address string)
- func (sys *SystemConfig) GetAddress(name ServiceName) (string, error)
- func (sys *SystemConfig) GetDomain() string
- func (sys *SystemConfig) GetURL(name ServiceName) (string, error)
- func (sys *SystemConfig) WaitForService(name ServiceName) error
- func (sys *SystemConfig) WaitForServiceToDie(name ServiceName) error
- type TimeStamp
- type Uuid
- type VcapApplication
- type VcapCredentials
- type VcapServiceEntry
- type VcapServices
- type Version
Constants ¶
const ( // ContentTypeJSON is the http content-type for JSON. ContentTypeJSON = "application/json" // ContentTypeText is the http content-type for plain text. ContentTypeText = "text/plain" )
const DefaultDomain = ".venicegeo.io"
const DefaultElasticsearchAddress = "localhost:9200"
const DefaultKafkaAddress = "localhost:9092"
const DefaultProtocol = "http"
const DefaultPzLoggerAddress = "localhost:14600"
const DefaultPzUuidgenAddress = "localhost:14800"
const GET, PUT, POST, DELETE, HEAD = "GET", "PUT", "POST", "DELETE", "HEAD"
Variables ¶
var EndpointPrefixes = map[ServiceName]string{ PzDiscover: "", PzElasticSearch: "", PzKafka: "", PzLogger: "", PzUuidgen: "", PzWorkflow: "", PzsvcHello: "", PzServiceController: "", PzMetrics: "", PzIdam: "", }
var HealthcheckEndpoints = map[ServiceName]string{ PzDiscover: "", PzElasticSearch: "", PzKafka: "", PzLogger: "/", PzUuidgen: "/", PzWorkflow: "/", PzsvcHello: "/", PzServiceController: "", PzMetrics: "/", PzIdam: "", }
var JsonResponseDataTypes = map[string]string{}
var LocalPortNumbers = map[ServiceName]string{ PzWorkflow: "20000", PzLogger: "20001", PzUuidgen: "20002", PzDiscover: "20003", PzElasticSearch: "20004", PzServiceController: "20005", PzMetrics: "20006", PzKafka: "20007", PzsvcHello: "20008", PzGoCommon: "20009", PzGoCommonTest: "20010", PzIdam: "20011", }
Functions ¶
func GetApiKey ¶
GetApiKey retrieves the Pz API key for the given server, in this order:
(1) if $PZKEY present, use that (2) if ~/.pzkey exists, use that (3) error
And no, we don't uspport Windows.
func GetBasicAuthHeader ¶
func GetExternalIP ¶
GetExternalIP returns the "best"(?) IP address we can reasonably get. see: http://stackoverflow.com/a/23558495
func GetPiazzaServiceUrl ¶
func GetPiazzaServiceUrl(serviceName ServiceName) (string, error)
GetServiceServer returns the host name of the given service, based on $PZSERVER.
func GetPiazzaUrl ¶
GetPiazzaServer returns the URL of the $PZSERVER host, i.e. the public entry point.
func GetVarsFromStruct ¶
func GetVarsFromStructSkip ¶
func GinReturnJson ¶
func GinReturnJson(c *gin.Context, resp *JsonResponse)
func HTTPDelete ¶
Delete, because there is no http.Delete.
func InsertString ¶
func RemoveWhitespace ¶
func RequestAuthZAccess ¶
action auditString
func StructInterfaceToString ¶
func StructStringToInterface ¶
func UnmarshalNumber ¶
func ValueIsValidArray ¶
func ValueIsValidArray(value interface{}) bool
func WaitForService ¶
func WaitForService(name ServiceName, url string) error
func WaitForServiceToDie ¶
func WaitForServiceToDie(name ServiceName, url string) error
Types ¶
type FlightCheck ¶
type GenericServer ¶
type GenericServer struct { Sys *SystemConfig // contains filtered or unexported fields }
GenericServer is the basic framework for standing up a gin-based server. It has methods to Start and Stop as well as to define the routing paths.
func (*GenericServer) Configure ¶
func (server *GenericServer) Configure(routeData []RouteData) error
Configure will take the give RouteData and register them with the server.
func (*GenericServer) Start ¶
func (server *GenericServer) Start() (chan error, error)
Start will start the service. You must call Configure first.
func (*GenericServer) Stop ¶
func (server *GenericServer) Stop() error
Stop will request the server to shutdown. It will wait for the service to die before returning.
type HeaderBuilder ¶
type HeaderBuilder struct {
// contains filtered or unexported fields
}
func NewHeaderBuilder ¶
func NewHeaderBuilder() *HeaderBuilder
func (*HeaderBuilder) AddBasicAuth ¶
func (builder *HeaderBuilder) AddBasicAuth(username, password string) *HeaderBuilder
func (*HeaderBuilder) AddHeader ¶
func (builder *HeaderBuilder) AddHeader(key, value string) *HeaderBuilder
func (*HeaderBuilder) AddJsonContentType ¶
func (builder *HeaderBuilder) AddJsonContentType() *HeaderBuilder
func (*HeaderBuilder) GetHeader ¶
func (builder *HeaderBuilder) GetHeader() [][2]string
type Http ¶
type Http struct { FlightCheck FlightCheck ApiKey string BaseUrl string User string Pass string }
func (*Http) PzDelete ¶
func (h *Http) PzDelete(endpoint string) *JsonResponse
func (*Http) PzGet ¶
func (h *Http) PzGet(endpoint string) *JsonResponse
func (*Http) PzGet2 ¶
func (h *Http) PzGet2(endpoint string, input interface{}) *JsonResponse
func (*Http) PzPost ¶
func (h *Http) PzPost(endpoint string, input interface{}) *JsonResponse
func (*Http) PzPut ¶
func (h *Http) PzPut(endpoint string, input interface{}) *JsonResponse
type HttpQueryParams ¶
type HttpQueryParams struct {
// contains filtered or unexported fields
}
HttpQueryParams holds a list of the query parameters of a URL, e.g.
...?count=8&foo=bar
We don't want to pass http.Request objects into the Services classes (and certainly not a gin.Context!), and we need this kind of information a lot, so we'll keep a special data structure which actually understands the semantics as well as the syntax.
func NewQueryParams ¶
func NewQueryParams(request *http.Request) *HttpQueryParams
NewQueryParams creates an HttpQueryParams object from an http.Request.
func (*HttpQueryParams) AddString ¶
func (params *HttpQueryParams) AddString(key string, value string)
AddString adds a key and string value to the parameter set, e.g. "?foo=bar".
func (*HttpQueryParams) AddTime ¶
func (params *HttpQueryParams) AddTime(key string, value time.Time)
AddTime adds a key and time value to the parameter set.
func (*HttpQueryParams) GetAsID ¶
func (params *HttpQueryParams) GetAsID(key string, defalt string) (Ident, error)
GetAsID retrieves the (string) value of a key from parameter set and returns it as an Ident.
func (*HttpQueryParams) GetAsInt ¶
func (params *HttpQueryParams) GetAsInt(key string, defalt int) (int, error)
GetAsInt retrieves the (string) value of a key from parameter set and returns it as an int.
func (*HttpQueryParams) GetAsSortOrder ¶
func (params *HttpQueryParams) GetAsSortOrder(key string, defalt SortOrder) (SortOrder, error)
GetAsSortOrder retrieves the (string) value of a key from parameter set and returns it as SortOrder value.
func (*HttpQueryParams) GetAsString ¶
func (params *HttpQueryParams) GetAsString(key string, defalt string) (string, error)
GetAsString retrieves the (string) value of a key from parameter set and returns it.
func (*HttpQueryParams) GetAsTime ¶
GetAsTime retrieves the (string) value of a key from parameter set and returns it as time value.
func (*HttpQueryParams) GetCount ¶
func (params *HttpQueryParams) GetCount(defalt int) (int, error)
GetCount retrieves the value of the "count" parameter.
func (*HttpQueryParams) GetPage ¶
func (params *HttpQueryParams) GetPage(defalt int) (int, error)
GetPage retrieves the value of the "page" parameter.
func (*HttpQueryParams) GetPerPage ¶
func (params *HttpQueryParams) GetPerPage(defalt int) (int, error)
GetPerPage retrieves the value of the "perPage" parameter.
func (*HttpQueryParams) GetSortBy ¶
func (params *HttpQueryParams) GetSortBy(defalt string) (string, error)
GetSortBy retrieves the value of the "sortBy" parameter.
func (*HttpQueryParams) GetSortOrder ¶
func (params *HttpQueryParams) GetSortOrder(defalt SortOrder) (SortOrder, error)
GetSortOrder retrieves the value of the "order" parameter.
func (*HttpQueryParams) String ¶
func (params *HttpQueryParams) String() string
String returns the parameter list expressed in URL style.
type Ident ¶
type Ident string
Ident is the type used for representing ID values.
const NoIdent Ident = ""
NoIdent is the "empty" ID value.
type JsonPagination ¶
type JsonPagination struct { Count int `json:"count"` // only used when writing output Page int `json:"page"` PerPage int `json:"perPage"` SortBy string `json:"sortBy"` Order SortOrder `json:"order"` }
JsonPagination is the Piazza model for pagination json responses.
func NewJsonPagination ¶
func NewJsonPagination(params *HttpQueryParams) (*JsonPagination, error)
NewJsonPagination creates a JsonPagination object. The default values will be overwritten with any appropriate values from the params list.
func (*JsonPagination) EndIndex ¶
func (p *JsonPagination) EndIndex() int
EndIndex returns the index number of the last element to be used.
func (*JsonPagination) StartIndex ¶
func (p *JsonPagination) StartIndex() int
StartIndex returns the index number of the first element to be used.
func (*JsonPagination) String ¶
func (p *JsonPagination) String() string
String returns a URL-style string of the pagination settings.
func (*JsonPagination) SyncPagination ¶
func (format *JsonPagination) SyncPagination(dslString string) (string, error)
type JsonResponse ¶
type JsonResponse struct { StatusCode int `json:"statusCode" binding:"required"` // only 2xxx -- Data is required (and Type too) // Type is a string, taken from the Java model list Type string `json:"type,omitempty"` Data interface{} `json:"data,omitempty" binding:"required"` Pagination *JsonPagination `json:"pagination,omitempty"` // optional // only 4xx and 5xx -- Message is required Message string `json:"message,omitempty"` Origin string `json:"origin,omitempty"` // optional Inner *JsonResponse `json:"inner,omitempty"` // optional // optional Metadata interface{} `json:"metadata,omitempty"` }
func (*JsonResponse) ExtractData ¶
func (resp *JsonResponse) ExtractData(output interface{}) error
given a JsonResponse object returned from an http call, and with Data set convert it to the given output type (formerly called SuperConverter)
func (*JsonResponse) IsError ¶
func (resp *JsonResponse) IsError() bool
func (*JsonResponse) SetType ¶
func (resp *JsonResponse) SetType() error
func (*JsonResponse) String ¶
func (resp *JsonResponse) String() string
func (*JsonResponse) ToError ¶
func (resp *JsonResponse) ToError() error
type RouteData ¶
type RouteData struct { Verb string Path string Handler gin.HandlerFunc }
RouteData describes one server route: which http verb, the path string, and the handler to use.
type ServiceName ¶
type ServiceName string
const ( PzDiscover ServiceName = "pz-discover" PzElasticSearch ServiceName = "pz-elasticsearch" PzGoCommon ServiceName = "PZ-GOCOMMON" // not a real service, just for testing PzGoCommonTest ServiceName = "PZ-GOCOMMONTEST" // not a real service, just for testing PzKafka ServiceName = "pz-kafka" PzLogger ServiceName = "pz-logger" PzUuidgen ServiceName = "pz-uuidgen" PzWorkflow ServiceName = "pz-workflow" PzsvcHello ServiceName = "pzsvc-hello" PzServiceController ServiceName = "pz-servicecontroller" PzMetrics ServiceName = "pz-metrics" PzIdam ServiceName = "pz-idam" )
type ServicesMap ¶
type ServicesMap map[ServiceName]string
type SimpleFlightCheck ¶
func (*SimpleFlightCheck) Postflight ¶
func (fc *SimpleFlightCheck) Postflight(code int, obj string) error
type SortOrder ¶
type SortOrder string
SortOrder indicates ascending (1,2,3) or descending (3,2,1) order.
type SystemConfig ¶
type SystemConfig struct { // our own service Name ServiceName Address string BindTo string Space string // int or stage or prod or... PiazzaSystem string // System-level username // contains filtered or unexported fields }
func NewSystemConfig ¶
func NewSystemConfig(serviceName ServiceName, requiredServices []ServiceName) (*SystemConfig, error)
func (*SystemConfig) AddService ¶
func (sys *SystemConfig) AddService(name ServiceName, address string)
it is explicitly allowed for outsiders to update an existing service, but we'll log it just to be safe
func (*SystemConfig) GetAddress ¶
func (sys *SystemConfig) GetAddress(name ServiceName) (string, error)
func (*SystemConfig) GetDomain ¶
func (sys *SystemConfig) GetDomain() string
func (*SystemConfig) GetURL ¶
func (sys *SystemConfig) GetURL(name ServiceName) (string, error)
func (*SystemConfig) WaitForService ¶
func (sys *SystemConfig) WaitForService(name ServiceName) error
func (*SystemConfig) WaitForServiceToDie ¶
func (sys *SystemConfig) WaitForServiceToDie(name ServiceName) error
type TimeStamp ¶
TimeStamp is used for the timeStamp field of a syslog.Message, but it is here in pz-gocommon because it may be generally useful.
A Piazza timestamp must always be in RFC3339 format and in UTC. That is, we use yyyy-MM-dd'T'HH:mm:ss.SSSZ, with three caveats: (1) the ".SSS" (fractional seconds) part is optional (2) if the fractional part is present, there may actually be 1-7 digits used (3) however, if the fractional part is present when reading in or writing out, then the system may silently truncate or round to only three digits (milliseconds).
There are three basic operations: Now, Parse, and String. In these functions, note how we always are careful to round the time to milliseconds and then convert it to UTC before proceeding with any usages of Time objects or time strings.
Note that when Go marshals a Time object into JSON, it uses the "RFC3339Nano" format which may have several fractional digits. Note also that when storing a time object into Elasticsearch, the entire fractional part may be truncated to zero fractional digits (second accuracy) or three fractional digits (millisecond accuracy).
func NewTimeStamp ¶
func NewTimeStamp() TimeStamp
func ParseTimeStamp ¶
func (TimeStamp) MarshalJSON ¶
func (*TimeStamp) UnmarshalJSON ¶
type Uuid ¶
type Uuid []byte
type VcapApplication ¶
type VcapApplication struct { ApplicationID string `json:"application_id"` ApplicationName string `json:"application_name"` ApplicationURIs []string `json:"application_uris"` ApplicationVersion string `json:"application_version"` Limits map[string]int `json:"limits"` Name string `json:"name"` SpaceId string `json:"space_id"` SpaceName string `json:"space_name"` URIs []string `json:"uris"` Users interface{} `json:"users"` // don't know what the datattype actually is Version string `json:"version"` // contains filtered or unexported fields }
func NewVcapApplication ¶
func NewVcapApplication(serviceName ServiceName) (*VcapApplication, error)
func (*VcapApplication) GetAddress ¶
func (vcap *VcapApplication) GetAddress() string
func (*VcapApplication) GetBindToPort ¶
func (vcap *VcapApplication) GetBindToPort() string
func (*VcapApplication) GetDomain ¶
func (vcap *VcapApplication) GetDomain() string
func (*VcapApplication) GetName ¶
func (vcap *VcapApplication) GetName() ServiceName
type VcapCredentials ¶
type VcapCredentials struct {
Host string `json:"host"`
}
type VcapServiceEntry ¶
type VcapServiceEntry struct { Credentials VcapCredentials `json:"credentials"` Label string `json:"label"` Name string `json:"name"` SyslogDrainUrl string `json:"syslog_drain_url"` Tags []string `json:"tags"` }
type VcapServices ¶
type VcapServices struct { UserProvided []VcapServiceEntry `json:"user-provided"` Services map[ServiceName]string }
func NewVcapServices ¶
func NewVcapServices() (*VcapServices, error)