Documentation
¶
Index ¶
- Constants
- func Err(c *fasthttp.RequestCtx, err error)
- func GenericError(err error)
- func In(x, y, z int) int
- func InString(x int, y string, z, def int) int
- func Int(s string) int
- func Paginate(page, limit string, maxLimit int) string
- func RandomString(n int) string
- func SafeUsername(s string) string
- func SanitiseString(s string) string
- func Sort(md MethodData, config SortConfiguration) string
- type CodeMessager
- type MethodData
- type Privileges
- type ResponseBase
- type Settings
- type SortConfiguration
- type Token
- type UnixTimestamp
- type UpdateQuery
- type UserPrivileges
- type WhereClause
Constants ¶
const ( MATCH_CREATION = "MATCH_CREATION" MATCH_HOST_ASSIGNMENT = "MATCH_HOST_ASSIGNMENT" MATCH_USER_JOIN = "MATCH_USER_JOIN" MATCH_USER_LEFT = "MATCH_USER_LEFT" MATCH_DISBAND = "MATCH_DISBAND" MATCH_GAME_PLAYTHROUGH = "MATCH_GAME_PLAYTHROUGH" )
const ( PrivilegeRead = 1 << iota // used to be to fetch public data, such as user information etc. this is deprecated. PrivilegeReadConfidential // (eventual) private messages, reports... of self PrivilegeWrite // change user information, write into confidential stuff... PrivilegeManageBadges // can change various users' badges. PrivilegeBetaKeys // can add, remove, upgrade/downgrade, make public beta keys. PrivilegeManageSettings // maintainance, set registrations, global alerts, bancho settings PrivilegeViewUserAdvanced // can see user email, and perhaps warnings in the future, basically. PrivilegeManageUser // can change user email, allowed status, userpage, rank, username... PrivilegeManageRoles // translates as admin, as they can basically assign roles to anyone, even themselves PrivilegeManageAPIKeys // admin permission to manage user permission, not only self permissions. Only ever do this if you completely trust the application, because this essentially means to put the entire ripple database in the hands of a (potentially evil?) application. PrivilegeBlog // can do pretty much anything to the blog, and the documentation. PrivilegeAPIMeta // can do /meta API calls. basically means they can restart the API server. PrivilegeBeatmap // rank/unrank beatmaps. also BAT when implemented )
These are the various privileges a token can have.
Variables ¶
This section is empty.
Functions ¶
func GenericError ¶
func GenericError(err error)
GenericError is just an error. Can't make a good description.
func In ¶
In picks x if y < x, picks z if y > z, or if none of the previous conditions is satisfies, it simply picks y.
func InString ¶
InString takes y as a string, also allows for a default value should y be invalid as a number.
func SafeUsername ¶
SafeUsername makes a string lowercase and replaces all spaces with underscores.
func SanitiseString ¶
SanitiseString removes all control codes from a string.
func Sort ¶
func Sort(md MethodData, config SortConfiguration) string
Sort allows the request to modify how the query is sorted.
Types ¶
type CodeMessager ¶
CodeMessager is something that has the Code() and Message() methods.
func SimpleResponse ¶
func SimpleResponse(code int, message string) CodeMessager
SimpleResponse returns the most basic response.
type MethodData ¶
type MethodData struct { User Token DB *sqlx.DB R *redis.Client Ctx *fasthttp.RequestCtx }
MethodData is a struct containing the data passed over to an API method.
func (MethodData) ClientIP ¶
func (md MethodData) ClientIP() string
ClientIP implements a best effort algorithm to return the real client IP, it parses X-Real-IP and X-Forwarded-For in order to work properly with reverse-proxies such us: nginx or haproxy.
func (MethodData) Err ¶
func (md MethodData) Err(err error)
Err logs to stdout when there is an error
func (MethodData) HasQuery ¶
func (md MethodData) HasQuery(q string) bool
HasQuery returns true if the parameter is encountered in the querystring. It returns true even if the parameter is "" (the case of ?param&etc=etc)
func (MethodData) IsBearer ¶
func (md MethodData) IsBearer() bool
IsBearer tells whether the current token is a Bearer (oauth) token.
func (MethodData) Query ¶
func (md MethodData) Query(q string) string
Query is shorthand for md.C.Query.
func (MethodData) Unmarshal ¶
func (md MethodData) Unmarshal(into interface{}) error
Unmarshal unmarshals a request's JSON body into an interface.
type Privileges ¶
type Privileges uint64
Privileges is a bitwise enum of the privileges of an user's API key.
func OAuthPrivileges ¶
func OAuthPrivileges(scopes string) Privileges
OAuthPrivileges returns the equivalent in Privileges of a space-separated list of scopes.
func (Privileges) CanOnly ¶
func (p Privileges) CanOnly(userPrivs UserPrivileges) Privileges
CanOnly removes any privilege that the user has requested to have, but cannot have due to their rank.
func (Privileges) String ¶
func (p Privileges) String() string
type ResponseBase ¶
ResponseBase is the data that is always returned with an API request.
func (ResponseBase) GetCode ¶
func (r ResponseBase) GetCode() int
GetCode retrieves the response code.
func (ResponseBase) GetMessage ¶
func (r ResponseBase) GetMessage() string
GetMessage retrieves the response message.
func (*ResponseBase) SetCode ¶
func (r *ResponseBase) SetCode(i int)
SetCode changes the response code.
type Settings ¶
type Settings struct { APP_PORT int APP_DOMAIN string HANAYO_KEY string OSU_API_KEY string DB_SCHEME string DB_HOST string DB_PORT int DB_USER string DB_PASS string DB_NAME string REDIS_HOST string REDIS_PORT int REDIS_PASS string REDIS_DB int REDIS_USE_SSL bool REDIS_SSL_SERVER_NAME string DISCORD_CLIENT_ID string DISCORD_CLIENT_SECRET string DISCORD_REDIRECT_URI string }
func GetSettings ¶
func GetSettings() Settings
func LoadSettings ¶
func LoadSettings() Settings
type SortConfiguration ¶
type SortConfiguration struct { Allowed []string // Allowed parameters Default string DefaultSorting string // if empty, DESC Table string }
SortConfiguration is the configuration of Sort.
type Token ¶
type Token struct { ID int Value string UserID int TokenPrivileges Privileges UserPrivileges UserPrivileges }
Token is an API token.
func (Token) OnlyUserPublic ¶
OnlyUserPublic returns a string containing "(user.privileges & 1 = 1 OR users.id = <userID>)" if the user does not have the UserPrivilege AdminManageUsers, and returns "1" otherwise.
type UnixTimestamp ¶
UnixTimestamp is simply a time.Time, but can be used to convert an unix timestamp in the database into a native time.Time.
func (UnixTimestamp) MarshalJSON ¶
func (u UnixTimestamp) MarshalJSON() ([]byte, error)
MarshalJSON -> time.Time.MarshalJSON
func (*UnixTimestamp) Scan ¶
func (u *UnixTimestamp) Scan(src interface{}) error
Scan decodes src into an unix timestamp.
func (*UnixTimestamp) UnmarshalJSON ¶
func (u *UnixTimestamp) UnmarshalJSON(x []byte) error
UnmarshalJSON -> time.Time.UnmarshalJSON
type UpdateQuery ¶
type UpdateQuery struct { Parameters []interface{} // contains filtered or unexported fields }
UpdateQuery is simply an SQL update query, that can be built upon passed parameters.
func (*UpdateQuery) Add ¶
func (u *UpdateQuery) Add(field string, value interface{}) *UpdateQuery
Add adds a new field with correspective value to UpdateQuery
func (*UpdateQuery) Fields ¶
func (u *UpdateQuery) Fields() string
Fields retrieves the fields joined by a comma.
type UserPrivileges ¶
type UserPrivileges uint64
UserPrivileges represents a bitwise enum of the privileges of an user.
const ( UserPrivilegePublic UserPrivileges = 1 << iota UserPrivilegeNormal UserPrivilegeDonor AdminPrivilegeAccessRAP AdminPrivilegeManageUsers AdminPrivilegeBanUsers AdminPrivilegeSilenceUsers AdminPrivilegeWipeUsers AdminPrivilegeManageBeatmap AdminPrivilegeManageServer AdminPrivilegeManageSetting AdminPrivilegeManageBetaKey AdminPrivilegeManageReport AdminPrivilegeManageDocs AdminPrivilegeManageBadges AdminPrivilegeViewRAPLogs AdminPrivilegeManagePrivilege AdminPrivilegeSendAlerts AdminPrivilegeChatMod AdminPrivilegeKickUsers UserPrivilegePendingVerification UserPrivilegeTournamentStaff AdminPrivilegeCaker UserPrivilegePremium AdminPrivilegeFreezeUsers AdminPrivilegeManageNominators )
user/admin privileges
func (UserPrivileges) String ¶
func (p UserPrivileges) String() string
type WhereClause ¶
type WhereClause struct { Clause string Params []interface{} // contains filtered or unexported fields }
WhereClause is a struct representing a where clause. This is made to easily create WHERE clauses from parameters passed from a request.
func Where ¶
func Where(clause, passedParam string, allowedValues ...string) *WhereClause
Where is the same as WhereClause.Where, but creates a new WhereClause.
func (*WhereClause) And ¶
func (w *WhereClause) And() *WhereClause
And enables using AND instead of OR
func (*WhereClause) ClauseSafe ¶
func (w *WhereClause) ClauseSafe() string
ClauseSafe returns the clause, always containing something. If w.Clause is empty, it returns "WHERE 1".
func (*WhereClause) In ¶
func (w *WhereClause) In(initial string, fields ...[]byte) *WhereClause
In generates an IN clause. initial is the initial part, e.g. "users.id". Fields are the possible values. Sample output: users.id IN ('1', '2', '3')
func (*WhereClause) Where ¶
func (w *WhereClause) Where(clause, passedParam string, allowedValues ...string) *WhereClause
Where adds a new WHERE clause to the WhereClause.