Documentation ¶
Overview ¶
Package utils provides utils for web interaction and handling requests, project configuration, interaction with primitive types etc.
Index ¶
- Constants
- Variables
- func Contains(val string, arr []string) bool
- func ContainsAll(what []string, where []string) bool
- func FileExists(filename string) bool
- func GetUser(c *gin.Context) (*model.User, error)
- func InterfaceArrayToStringArray(i []interface{}) []string
- func ReadFile(path string) ([]byte, error)
- func RespondError(c *gin.Context, code int, payload interface{})
- func RespondJSON(c *gin.Context, code int, payload interface{})
- func RespondResult(c *gin.Context, payload interface{})
- func Substring(input string, start int, length int) string
- func ValidIntQueryParam(param string, min int, max int) (*int, error)
- func WaitForShutdown(srv *http.Server)
- type ClientConfig
- type Config
Constants ¶
const (
// AuthenticatedUserModelKey is a key used by auth middleware to store user model.
AuthenticatedUserModelKey = "AuthenticatedUserModelKey"
)
Variables ¶
var ErrIntParamInvalid = errors.New("int_param_invalid")
ErrIntParamInvalid indicates an error of a validated integer parameter.
ErrUnauthorized indicates bad user authentication.
Functions ¶
func ContainsAll ¶
ContainsAll returns true if "where" array contains each element from a "what" array.
func FileExists ¶
FileExists returns true if a file exists and no errors occurred.
func InterfaceArrayToStringArray ¶
func InterfaceArrayToStringArray(i []interface{}) []string
InterfaceArrayToStringArray converts interface array to a string array.
func RespondError ¶
RespondError writes provided payload to "error" field of a response JSON object with a provided HTTP code.
func RespondJSON ¶
RespondJSON writes provided payload to response as JSON with provided HTTP code.
func RespondResult ¶
RespondResult writes provided payload to "result" field of a response JSON object with a 200 HTTP code.
func ValidIntQueryParam ¶
ValidIntQueryParam validates provided string parameter as an integer in a [min, max] range.
func WaitForShutdown ¶
WaitForShutdown provides graceful shutdown of an HTTP server.
Types ¶
type ClientConfig ¶
ClientConfig is a config for oauth clients.
type Config ¶
type Config struct { Server struct { Port uint16 PathPrefixData string `yaml:"path_prefix_data"` } Clients map[string]ClientConfig Mongo data.MongoSettings Vk vk.Settings Jwt model.JwtSettings }
Config is a project config.
func ReadConfig ¶
ReadConfig maps yml config from path to Config struct. Edited: now private config moved to environment variables, and set from Drone CI secrets.