Documentation
¶
Overview ¶
Package helpers provides a set of utility functions used across gonawin app.
Index ¶
- Constants
- Variables
- func AreEmailsValid(emails []string) bool
- func ArgMaxInt64(arr []int64) (index int, max int64)
- func Contains(s []int64, value int64) (bool, int)
- func CopyToPointerStructure(tSrc interface{}, tDest interface{})
- func CountTerm(words []string, w string) int64
- func Error404(w http.ResponseWriter)
- func InitPointerStructure(pSrc interface{}, pDest interface{}, fieldsToKeep arrayOfStrings)
- func Insert(s []int64, value int64, i int64) []int64
- func Intersect(a string, b string) string
- func IsEmailValid(email string) bool
- func IsPasswordValid(password string) bool
- func IsStringValid(s string) bool
- func IsUsernameValid(username string) bool
- func KeepFields(t interface{}, fieldsToKeep arrayOfStrings)
- func MergeIds(teamIds []byte, id int64) string
- func RemovefromIds(teamIds []byte, id int64) (string, error)
- func SetOfStrings(s string) []string
- func SliceContains(slice []string, s string) bool
- func StringContains(strToSplit string, s string) bool
- func TeamImageURL(name string, id int64) string
- func TournamentImageURL(name string, id int64) string
- func TransformFromArrayOfPointers(pArraySrc interface{}, pArrayDest interface{}, fieldsToKeep arrayOfStrings)
- func TransformFromArrayOfValues(pArraySrc interface{}, pArrayDest interface{}, fieldsToKeep arrayOfStrings)
- func TrimLower(s string) string
- func UserImageURL(name string, id int64) string
- type BadRequest
- type Forbidden
- type InternalServerError
- type NotFound
- type Unauthorized
Constants ¶
const ( // generic ErrorCodeNotSupported = "Not Supported" ErrorCodeInternal = "Internal error" ErrorCodeNotFound = "Not Found" ErrorCodeNameCannotBeEmpty = "Name field cannot be empty" // sessions ErrorCodeSessionsAccessTokenNotValid = "Access token is not valid" ErrorCodeSessionsForbiden = "You are not authorized to log in to gonawin" ErrorCodeSessionsUnableToSignin = "Error occurred during signin process" ErrorCodeSessionsCannotGetTempCredentials = "Error getting temporary credentials" ErrorCodeSessionsCannotSetSecretValue = "Error setting 'secret' value" ErrorCodeSessionsCannotGetSecretValue = "Error getting 'secret' value" ErrorCodeSessionsCannotGetRequestToken = "Error getting request token" ErrorCodeSessionsCannotGetUserInfo = "Error getting user info from Twitter" ErrorCodeSessionsCannotGetGoogleLoginURL = "Error getting Google accounts login URL" // users ErrorCodeUserNotFound = "User not found" ErrorCodeUserNotFoundCannotUpdate = "User not found, unable to update" ErrorCodeUserNotFoundCannotDelete = "User not found, unable to delete" ErrorCodeUserNotFoundCannotInvite = "User not found, unable to send invitation" ErrorCodeUserCannotUpdate = "Could not update user" ErrorCodeUsersCannotUpdate = "Could not update users" ErrorCodeUsersCannotPublishScore = "Could not pusblish score activities" ErrorCodeUserIsTeamAdminCannotDelete = "User cannot be deleted because he is team admin" ErrorCodeUserIsTournamentAdminCannotDelete = "User cannot be deleted because he is tournament admin" // teams ErrorCodeTeamAlreadyExists = "Sorry, that team already exists" ErrorCodeTeamCannotCreate = "Could not create the team" ErrorCodeTeamNotFound = "Team not found" ErrorCodeTeamNotFoundCannotUpdate = "Team not found, unable to update" ErrorCodeTeamNotFoundCannotDelete = "Team not found, unable to delete" ErrorCodeTeamNotFoundCannotInvite = "Team not found, unable to send invitation" ErrorCodeTeamUpdateForbiden = "Team can only be updated by the team administrator" ErrorCodeTeamDeleteForbiden = "Team can only be deleted by the team administrator" ErrorCodeTeamCannotUpdate = "Could not update team" ErrorCodeTeamCannotInvite = "Could not send invitation" ErrorCodeTeamRequestNotFound = "Request not found" ErrorCodeTeamMemberNotFound = "Member not found" ErrorCodeTeamAdminCannotLeave = "Team administrator cannot leave the team" ErrorCodeTeamPrivateJoinForbiden = "Private Team cannot be joined without consent. Please request an invitation" ErrorCodeTeamRequestAlreadySent = "Sorry, you already requested an invitation" //tournaments ErrorCodeTournamentAlreadyExists = "Sorry, that tournament already exists" ErrorCodeTournamentCannotCreate = "Could not create the team" ErrorCodeTournamentNotFound = "Tournament not found" ErrorCodeTournamentNotFoundCannotUpdate = "Tournament not found, unable to update" ErrorCodeTournamentNotFoundCannotDelete = "Tournament not found, unable to delete" ErrorCodeTournamentUpdateForbiden = "Tournament can only be updated by the team administrator" ErrorCodeTournamentDeleteForbiden = "Tournament can only be deleted by the team administrator" ErrorCodeTournamentCannotUpdate = "Could not update tournament" ErrorCodeTournamentCannotSearch = "Something went wrong, we are unable to perform search query" ErrorCodeMatchCannotUpdate = "Something went wrong, unable to update match" ErrorCodeMatchesCannotUpdate = "Something went wrong, unable to update matches" ErrorCodeMatchNotFoundCannotUpdate = "Match not found, unable to update match" ErrorCodeMatchNotFound = "Match not found" ErrorCodeMatchNotFoundCannotSetPrediction = "Match not found, unable to set prediction" ErrorCodeCannotSetPrediction = "Something went wrong, unable to set prediction" ErrorCodeNotAllowedToSetPrediction = "You have to join the tournament to be able to set a predict for this match" ErrorCodeTeamsCannotUpdate = "Could not update teams" // invite ErrorCodeInviteNoEmailAddr = "No email address has been entered" ErrorCodeInviteEmailsInvalid = "Emails list is not properly formatted" ErrorCodeInviteEmailCannotSend = "Sorry, we were unable to send the Email" )
errors
Variables ¶
var PasswordRegexp = regexp.MustCompile(`^.{3,20}$`)
PasswordRegexp is the regexp for password.
var UsernameRegExp = regexp.MustCompile(`^[\sa-zA-Z0-9_-]{3,20}$`)
UsernameRegExp is the regexp for username.
Functions ¶
func AreEmailsValid ¶
AreEmailsValid checks if an array of emails is valid.
func ArgMaxInt64 ¶
ArgMaxInt64 returns the index and the max value.
func Contains ¶
Contains indicates if a value exists in a given slice. If the value exists, its position in the slice is returned otherwise -1.
func CopyToPointerStructure ¶
func CopyToPointerStructure(tSrc interface{}, tDest interface{})
CopyToPointerStructure copies structure fields to structure pointer fields. from two structures source and destination. structures defined as follows: both structures have the same fields destination structure field types are pointers of the source types example:
type TA struct { Field1 string Field2 string IsSomething bool }
type TB struct { Field1 *string `json:",omitempty"` Field2 *string `json:",omitempty"` IsSomething *bool `json:",omitempty"` }
use source structure to build destination structure
func Error404 ¶
func Error404(w http.ResponseWriter)
Error404 writes a 404 not found in ResponseWriter.
func InitPointerStructure ¶
func InitPointerStructure(pSrc interface{}, pDest interface{}, fieldsToKeep arrayOfStrings)
InitPointerStructure initializes structure with pointer fields from two structures, source and destination. structures defined as follows: both structures have the same fields destination structure field types are pointers of the source types example:
type TA struct { Field1 string Field2 string IsSomething bool }
type TB struct { Field1 *string `json:",omitempty"` Field2 *string `json:",omitempty"` IsSomething *bool `json:",omitempty"` }
use source structure to build destination structure and at the same time set to nil all fields of Destination structure not present in array fieldsToKeep we suppose that pDest is a structure of pointer types and fieldsToKeep is an array of the fields you wish to keep.
func Insert ¶
Insert inserts new value into a slice at a given position source: https://code.google.com/p/go-wiki/wiki/SliceTricks
func Intersect ¶
Intersect computes the instersection of two strings. From two strings with format "str1 str2" and "str2 str3" in this example the result is "str2".
func IsEmailValid ¶
IsEmailValid returns true if string email has the form a@b.c
func IsPasswordValid ¶
IsPasswordValid returns true for all passwords that are between 3 and 20 characters.
func IsStringValid ¶
IsStringValid returns true if string is not empty.
func IsUsernameValid ¶
IsUsernameValid returns true is username is a string between 3 and 20 characters. note: added \s just temporary until user name is splited with name and last name username should not have whitespaces
func KeepFields ¶
func KeepFields(t interface{}, fieldsToKeep arrayOfStrings)
KeepFields sets to nil all fields of t structure not present in array. We suppose that t is a structure of pointer types and fieldsToKeep is an array of the fields you wish to keep.
func MergeIds ¶
MergeIds merges ids in slice of byte with id if it is not already there if id is already in the slice return empty string.
func RemovefromIds ¶
RemovefromIds removes id from slice of byte with ids.
func SetOfStrings ¶
SetOfStrings returns a set of string for a given strings.
func SliceContains ¶
SliceContains checks if a given string exists in a slice of strings.
func StringContains ¶
StringContains checks if a given string exists in a string.
func TeamImageURL ¶
TeamImageURL returns the team image URL for a given name and id.
func TournamentImageURL ¶
TournamentImageURL returns the tournament image URL for a given name and id.
func TransformFromArrayOfPointers ¶
func TransformFromArrayOfPointers(pArraySrc interface{}, pArrayDest interface{}, fieldsToKeep arrayOfStrings)
TransformFromArrayOfPointers works like InitPointerStructure but for arrays. source array has values.
func TransformFromArrayOfValues ¶
func TransformFromArrayOfValues(pArraySrc interface{}, pArrayDest interface{}, fieldsToKeep arrayOfStrings)
TransformFromArrayOfValues works like InitPointerStructure but for arrays. source array has pointers.
func TrimLower ¶
TrimLower returns a lower case slice of the string s, with all leading and trailing white space removed, as defined by Unicode.
func UserImageURL ¶
UserImageURL returns the user image URL for a given name and id.
Types ¶
type BadRequest ¶
type BadRequest struct {
Err error
}
BadRequest is handled by setting the status code in the reply to StatusBadRequest.
func (*BadRequest) Error ¶
func (e *BadRequest) Error() string
Implementation of error, returns string error on Err structure.
type Forbidden ¶
type Forbidden struct {
Err error
}
Forbidden is handled by setting the status code in the reply to StatusForbidden.
type InternalServerError ¶
type InternalServerError struct {
Err error
}
InternalServerError is handled by setting the status code in the reply to StatusInternalServerError.
func (*InternalServerError) Error ¶
func (e *InternalServerError) Error() string
Implementation of error, returns string error on Err structure.
type NotFound ¶
type NotFound struct {
Err error
}
NotFound is handled by setting the status code in the reply to StatusNotFound.
type Unauthorized ¶
type Unauthorized struct {
}Unauthorized is handled by setting the status code in the reply to StatusUnauthorized.
func (*Unauthorized) Error ¶
func (e *Unauthorized) Error() string
Implementation of error, returns string error on Err structure.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package auth provides the functions needed to get a user information.
|
Package auth provides the functions needed to get a user information. |
Package handlers provides a set of functions to manipulate http.HandlerFunc at a route level.
|
Package handlers provides a set of functions to manipulate http.HandlerFunc at a route level. |
Package log provide a set of function to log in gonawin app.
|
Package log provide a set of function to log in gonawin app. |
Package memcache provides a set of functions to use memcache in gonawin.
|
Package memcache provides a set of functions to use memcache in gonawin. |
Package templates provides a set of functions to encode data in a http.ResponseWriter.
|
Package templates provides a set of functions to encode data in a http.ResponseWriter. |