utils

package
v0.0.0-...-5f6e6a3 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultFindFromRequest

func DefaultFindFromRequest(r *http.Request, db *gorm.DB, data interface{}) error

func DefaultQueryAll

func DefaultQueryAll(r *http.Request, q *gorm.DB) *gorm.DB

func GetSha

func GetSha(b []byte) string

GetSha return a string of SHA from bytes

func Has

func Has(b, flag RightBits) bool

Has a Right

func HasRights

func HasRights(r *http.Request, rights RightBits, f func(r *http.Request, rights RightBits) bool) bool

HasRights check for correct role

func HasRightsRequest

func HasRightsRequest(r *http.Request, rights RightBits) bool

HasRightsRequest check for correct role

func Message

func Message(status bool, message string) map[string]interface{}

Message to give a status and reason about errors or if data cannot be retrieved

func ReadFloatURL

func ReadFloatURL(r *http.Request, param string) (float64, error)

ReadIntURL read an URL parameter

func ReadInt

func ReadInt(r *http.Request, param string, v int64) (int64, error)

ReadInt return an int or a default value

func ReadIntURL

func ReadIntURL(r *http.Request, param string) (int, error)

ReadIntURL read an URL parameter

func ReadJSON

func ReadJSON(r *http.Request, v interface{}) error

ReadJSON read a json or return a response

func ReadURL

func ReadURL(r *http.Request, param string) string

ReadURL read an URL parameter

func Respond

func Respond(w http.ResponseWriter, data map[string]interface{})

Respond Create a JSON response with headers

func RespondCode

func RespondCode(w http.ResponseWriter, data map[string]interface{}, statusCode int)

RespondCode Create a JSON response with headers

Types

type JSON

type JSON []byte

JSON return a json type

func (JSON) Equals

func (j JSON) Equals(j1 JSON) bool

Equals ...

func (JSON) IsNull

func (j JSON) IsNull() bool

IsNull ...

func (JSON) MarshalJSON

func (j JSON) MarshalJSON() ([]byte, error)

MarshalJSON return byte

func (*JSON) New

func (j *JSON) New(value interface{}) error

New to create from scratch bject

func (*JSON) Scan

func (j *JSON) Scan(value interface{}) error

Scan to scan from sql value

func (JSON) To

func (j JSON) To(ret interface{}) error

To return JSON to type must be transfered via pointer &val

func (JSON) ToInterface

func (j JSON) ToInterface() map[string]interface{}

ToInterface to return an string interface

func (*JSON) UnmarshalJSON

func (j *JSON) UnmarshalJSON(data []byte) error

UnmarshalJSON return JSON

func (JSON) Value

func (j JSON) Value() (driver.Value, error)

Value to return the current value in string

type RightBits

type RightBits uint32

RightBits set a right

const (
	NoRight RightBits = 0
)

func Clear

func Clear(b, flag RightBits) RightBits

Clear a right

func Set

func Set(b, flag RightBits) RightBits

Set a right

func Toggle

func Toggle(b, flag RightBits) RightBits

Toggle a Right

func (RightBits) Clear

func (b RightBits) Clear(flag RightBits) RightBits

Clear a right

func (RightBits) Has

func (b RightBits) Has(flag RightBits) bool

Has a right

func (RightBits) Set

func (b RightBits) Set(flag RightBits) RightBits

Set a right

func (RightBits) Toggle

func (b RightBits) Toggle(flag RightBits) RightBits

Toggle a right

type Route

type Route struct {
	Name          string           `json:"name"`
	Method        string           `json:"method"`
	Pattern       string           `json:"pattern"`
	HandlerFunc   http.HandlerFunc `json:"-"`
	Authorization uint32           `json:"auth"`
}

Route define a route with url and rights required to access it

type Routes

type Routes []Route

Routes an array of route

func (Routes) Append

func (r Routes) Append(routes []Route) Routes

Append Add routes to Routes

func (Routes) Get

func (r Routes) Get(name string) Route

Get Return route by name

type Token

type Token struct {
	UserId     uint
	UserRights RightBits
	jwt.StandardClaims
}

Token JWT claims struct

func GetAuthenticatedToken

func GetAuthenticatedToken(r *http.Request) (Token, bool)

GetAuthenticatedToken return the Authentication token if exists in context

Jump to

Keyboard shortcuts

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