Documentation ¶
Index ¶
- Constants
- Variables
- func ArrayFind(a []interface{}, val interface{}) interface{}
- func CreateNewUUID() string
- func GetLanguage(c *gin.Context) string
- func GetMessage(msgID, lang string) string
- func OnlyNumbers(str string) string
- func ParseToInt64(ID string) (int64, error)
- func ValidateUserAge(birthDate *time.Time) (valid bool)
- type Claim
- type ErrorData
- type Message
- type ResourceType
- type Response
- type Token
Constants ¶
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
const ( AuthorizationMethodBearer = "Bearer" AuthorizationMethodBasic = "Basic" )
Supported authorization methods
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
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
const ( ParamUserID = "userID" ParamLanguage = "lang" )
Parameters defined in the API urls
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
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
const ( MsgContactThanks = "msg_contact_thanks" MsgContactThanks48Hours = "msg_contact_thanks_48_hours" MsgThanksForYourFeedback = "thanks_for_your_feedback" )
API messages
const ( DefaultLanguage = "es" TranslationsFolder = "lang/" SupportedLanguages = "es" )
Message constants
Variables ¶
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 GetLanguage ¶
GetLanguage returns the specified of default language
func GetMessage ¶
GetMessage returns the text for msgID, in the specific language
func ParseToInt64 ¶
ParseToInt64 Parses string to int64.
func ValidateUserAge ¶
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
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 ¶
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 ¶
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
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