api

package module
v0.0.0-...-b373d3e Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2020 License: MIT Imports: 22 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNotFound     = errors.New("NotFound")
	ErrorConflict     = errors.New("Conflict")
	ErrorPassword     = errors.New("Password")
	ErrorUserNotFound = errors.New("user not found")
)
View Source
var CORSConfig = middleware.CORSWithConfig(middleware.CORSConfig{
	AllowOrigins:     strings.Split(os.Getenv("ALLOW_ORIGINS"), ","),
	AllowHeaders:     []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
	AllowCredentials: true,
})

Functions

func Btoi

func Btoi(b bool) int

func DeleteSession

func DeleteSession(c echo.Context)

func FormatRequestPrint

func FormatRequestPrint(r *http.Request) string

func GetAccessToken

func GetAccessToken(key interface{}) ([]byte, error)

func Itob

func Itob(i int) bool

func RedisSession

func RedisSession() echo.MiddlewareFunc

func RespConflict

func RespConflict(k string, i interface{}) interface{}

func RespCreated

func RespCreated() interface{}

func RespCustom

func RespCustom(m string, k *string, i interface{}) interface{}

func RespInternelServerError

func RespInternelServerError() interface{}

func RespNoContent

func RespNoContent(k string, i interface{}) interface{}

func SessionAuth

func SessionAuth(next echo.HandlerFunc) echo.HandlerFunc

func SetSession

func SetSession(c echo.Context, user *UserSession)

Types

type AccessList

type AccessList struct {
	Access map[string]map[string][]string `json:"access"`
}

type Additional

type Additional map[string]interface{}

type ApiError

type ApiError struct {
	Error     error
	Model     string
	Line      int
	FileName  string
	UserEmail string
	UserUuid  string
}

func GetError

func GetError(err error) *ApiError

func (*ApiError) LogError

func (e *ApiError) LogError(c echo.Context, i interface{})

func (*ApiError) PrintErrorNoSession

func (e *ApiError) PrintErrorNoSession(c echo.Context, i interface{})

type GobSerializer

type GobSerializer struct{}

Gob serializer

func (GobSerializer) Deserialize

func (gs GobSerializer) Deserialize(d []byte, s *sessions.Session) error

func (GobSerializer) Serialize

func (gs GobSerializer) Serialize(s *sessions.Session) ([]byte, error)

type JsonError

type JsonError struct {
	Key   string
	Error string
}

func JsonErrorResponse

func JsonErrorResponse(e error) (j_list []JsonError)

type KeyGenFunc

type KeyGenFunc func() (string, error)

KeyGenFunc defines a function used by store to generate a key

type Model

type Model struct {
	Uuid    string `json:"uuid" validate:"required"`
	Name    string `json:"name" validate:"required"`
	Service string `json:"service" validate:"required"`
	Creator string `json:"owner" validate:"required"`
	Created int64  `json:"created" validate:"required"`
}

Model can be every model

type ModelCreate

type ModelCreate struct {
	Uuid    string `json:"uuid" validate:"required"`
	Name    string `json:"name" validate:"required"`
	Service string `json:"service" validate:"required"`
	Creator string `json:"owner" validate:"required"`
}

func (*ModelCreate) Model

func (m_create *ModelCreate) Model(created int64) *Model

type RedisStore

type RedisStore struct {
	// contains filtered or unexported fields
}

RedisStore stores gorilla sessions in Redis

func NewRedisStore

func NewRedisStore(client redis.UniversalClient) (*RedisStore, error)

NewRedisStore returns a new RedisStore with default configuration

func (*RedisStore) Get

func (s *RedisStore) Get(r *http.Request, name string) (*sessions.Session, error)

Get returns a session for the given name after adding it to the registry.

func (*RedisStore) KeyGen

func (s *RedisStore) KeyGen(f KeyGenFunc)

KeyGen sets the key generator function

func (*RedisStore) KeyPrefix

func (s *RedisStore) KeyPrefix(keyPrefix string)

KeyPrefix sets the key prefix to store session in Redis

func (*RedisStore) New

func (s *RedisStore) New(r *http.Request, name string) (*sessions.Session, error)

New returns a session for the given name without adding it to the registry.

func (*RedisStore) Options

func (s *RedisStore) Options(opts sessions.Options)

Options set options to use when a new session is created

func (*RedisStore) Save

func (s *RedisStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Save adds a single session to the response.

If the Options.MaxAge of the session is <= 0 then the session file will be deleted from the store. With this process it enforces the properly session cookie handling so no need to trust in the cookie management in the web browser.

func (*RedisStore) Serializer

func (s *RedisStore) Serializer(ss SessionSerializer)

Serializer sets the session serializer to store session

type ResponseMessage

type ResponseMessage struct {
	Message string                 `json:"message"`
	Data    map[string]interface{} `json:"data,omitempty"`
}

type SessionSerializer

type SessionSerializer interface {
	Serialize(s *sessions.Session) ([]byte, error)
	Deserialize(b []byte, s *sessions.Session) error
}

SessionSerializer provides an interface for serialize/deserialize a session

type UserRequest

type UserRequest struct {
	Uuid map[string]Additional `json:"uuid" validate:"required"`
}

func (*UserRequest) Filter

func (f *UserRequest) Filter() string

type UserSession

type UserSession struct {
	Uuid          string                         `json:"uuid"`
	Email         string                         `json:"email"`
	Confirmed     bool                           `json:"confirmed"`
	PrivacyPolicy bool                           `json:"privacy_policy"`
	Country       string                         `json:"country"`
	Access        map[string]map[string][]string `json:"access"`
	Additional    Additional                     `json:"additional"`
	Updated       int64                          `json:"updated"`
	Created       int64                          `json:"created"`
}

func GetUser

func GetUser(c echo.Context) (u *UserSession, contains bool)

Jump to

Keyboard shortcuts

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