api

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RealmUsers        = "users"
	RealmVenues       = "venues"
	HTTPTimeout       = time.Second * 10
	TimestampFormat   = "2006-01-02T15:04:05.000Z"
	AppInitVersioning = "versioning"
	AppInitURLs       = "urls"
	PlatformAndroid   = "android"
	PlatformIOS       = "ios"
	AppIDAndroid      = "lit.android"
	AppIDIOS          = "lit.ios"
	MaxFileUploadSize = int64(10240000) // 10MB
)

General constants

View Source
const (
	AuthorizationMethodBearer = "Bearer"
	AuthorizationMethodBasic  = "Basic"
)

Supported authorization methods

View Source
const (
	HTTPHeaderAuthorization  = "Authorization"
	HTTPHeaderAppName        = "AppName"
	HTTPHeaderPlatform       = "Platform"
	HTTPHeaderAppVersion     = "AppVersion"
	HTTPHeaderDeviceInfo     = "Device-Info"
	HTTPHeaderDeviceToken    = "Device-Token"
	HTTPHeaderAcceptLanguage = "Accept-Language"
	HTTPHeaderDeviceID       = "Device-ID"
)

HTTP headers used in the API

View Source
const (
	HandlerKeyTokenID      = "Token-ID"
	HandlerKeyClientID     = "Client-ID"
	HandlerKeyClientSecret = "Client-Secret"
	HandlerKeyLanguage     = "Lang"
	HandlerKeyDeviceInfo   = "Device-Info"
	HandlerKeyPlatform     = "Platform"
	HandlerKeyAppVersion   = "App-Version"
	HandlerKeyDeviceID     = "Device-ID"
)

Key names used to store info in the HTTP handlers

View Source
const (
	ParamUserID   = "userID"
	ParamLanguage = "lang"
)

Parameters defined in the API urls

View Source
const (
	QueryParameterPretty           = "pretty"
	QueryParameterCountry          = "country"
	QueryParameterLanguage         = "lang"
	QueryParameterUserData         = "user_data"
	QueryParameterFilter           = "filter"
	QueryParameterTimestamp        = "timestamp"
	QueryParameterSortOrder        = "sort_order"
	QueryParameterExternalUsername = "username"
)

Query parameters recognized by the API

View Source
const (
	ErrorInvalidToken            = "invalid_token"
	ErrorAuthService             = "err_auth_service"
	ErrorInternalError           = "internal_error"
	ErrorMissingParameters       = "missing_parameters"
	ErrorUserExists              = "user_exists"
	ErrorCountryNotSupported     = "invalid_country"
	ErrorInvalidRequest          = "invalid_request"
	ErrorUnkownUser              = "unknown_user"
	ErrorUnkownVenue             = "unknown_venue"
	ErrorAccountBlocked          = "account_blocked"
	ErrorInvalidParameters       = "invalid_parameters"
	ErrorFileTooBig              = "file_too_big"
	ErrorMissingInvite           = "missing_invite"
	ErrorExpectedBoolNotRecieved = "expected_bool_but_recieved_other"
	ErrorImageFormatNotSupported = "image_format_not_supported"
	ErrorImageSizeNotSupported   = "image_size_not_supported"
	ErrorForbiddenRequest        = "forbidden_request"
)

API error codes

View Source
const (
	MsgContactThanks         = "msg_contact_thanks"
	MsgContactThanks48Hours  = "msg_contact_thanks_48_hours"
	MsgThanksForYourFeedback = "thanks_for_your_feedback"
)

API messages

View Source
const (
	DefaultLanguage    = "es"
	TranslationsFolder = "lang/"
	SupportedLanguages = "es"
)

Message constants

Variables

View Source
var (
	ErrInternalError           = errors.New("Internal error")
	ErrAuthService             = errors.New("Error sending request to the Authorization Service")
	ErrAuthHeaderNotFound      = errors.New("Missing Authentication header")
	ErrBadRequest              = errors.New("Bad request")
	ErrUserNotFound            = errors.New("Invalid user")
	ErrInvalidToken            = errors.New("Invalid token")
	ErrAccountBlocked          = errors.New("Account blocked")
	ErrMissingRequiredFields   = errors.New("Missing required fields")
	ErrAwsNotEnabled           = errors.New("AWS not enabled")
	ErrAwsS3Timeout            = errors.New("Upload s3 timeout")
	ErrAwsUploadS3             = errors.New("Error upload s3 object")
	ErrUnregisterdUser         = errors.New("UNREGISTERED")
	ErrImageFormatNotSupported = errors.New("Image format not supported")
	ErrImageSizeNotSupported   = errors.New("Image size not supported")
)

Internal error types

Functions

func ArrayFind

func ArrayFind(a []interface{}, val interface{}) interface{}

ArrayFind searches for an element `val` within array `a`. If the value exists, it will be returned by the function.

func CreateNewUUID

func CreateNewUUID() string

CreateNewUUID creates a new UUID without dashes

func GetLanguage

func GetLanguage(c *gin.Context) string

GetLanguage returns the specified of default language

func GetMessage

func GetMessage(msgID, lang string) string

GetMessage returns the text for msgID, in the specific language

func OnlyNumbers

func OnlyNumbers(str string) string

OnlyNumbers extract only numbers from str

func ParseToInt64

func ParseToInt64(ID string) (int64, error)

ParseToInt64 Parses string to int64.

func ValidateUserAge

func ValidateUserAge(birthDate *time.Time) (valid bool)

ValidateUserAge validate user age

Types

type Claim

type Claim struct {
	Claims map[string]interface{} `json:"claims"`
}

Claim represents a request/response

type ErrorData

type ErrorData struct {
	Error       string    `json:"error,omitempty"`
	Description string    `json:"description,omitempty"`
	Fields      *[]string `json:"fields,omitempty"`
}

ErrorData is used to represent API errors

func (*ErrorData) Marshall

func (errData *ErrorData) Marshall() []byte

Marshall encodes ErrorData content to a json byte array

type Message

type Message struct {
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

Message is used to send no error responses to the client

type ResourceType

type ResourceType string

ResourceType is used to represent internal system resources like User

const (
	ResourceUser ResourceType = "USER"
)

API resources defined in the API, required to handle the authorization rules

type Response

type Response struct {
	ContentType    string
	Status         int
	Header         map[string]string
	ErrCode        string
	ErrDescription string
	Fields         *[]string
	Payload        []byte
	Language       string
}

Response represents a HTTP Response

func BuildBadRequestResponse

func BuildBadRequestResponse() *Response

BuildBadRequestResponse creates a tipical response for a 400 status code

func BuildEmptyUnauthorizedResponse

func BuildEmptyUnauthorizedResponse(realm, method string) *Response

BuildEmptyUnauthorizedResponse creates a 401 response, without any error details. It should be used when an authentication method was not supported.

func BuildForbiddenResponse

func BuildForbiddenResponse() *Response

BuildForbiddenResponse creates a 403 response, without any error details

func BuildInternalErrorResponse

func BuildInternalErrorResponse() *Response

BuildInternalErrorResponse creates a tipical response for a 500 status code

func BuildUnauthorizedResponse

func BuildUnauthorizedResponse(code, description, realm, method string) *Response

BuildUnauthorizedResponse creates a tipical response for a 401 status code

func (*Response) Send

func (response *Response) Send(w http.ResponseWriter)

Send writes the HTTP response in a http.ResponseWriter

func (*Response) String

func (response *Response) String() string

String returns a string representation of the error, suitable for including it in a HTTP header

type Token

type Token struct {
	ID           string `json:"id,omitempty"`
	Grant        string `json:"grant,omitempty"`
	ClientSecret string `json:"client_secret,omitempty"`
	Token        string `json:"token,omitempty"`
	Refresh      string `json:"refresh_token,omitempty"`
	Type         string `json:"token_type,omitempty"`
	ExpiresIn    int    `json:"expires_in,omitempty"`
	Firebase     struct {
		Token string `json:"token,omitempty"`
	} `json:"firebase,omitempty"`
}

Token is used to get responses from the auth service and forward it to the client

Jump to

Keyboard shortcuts

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