service

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

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

Go to latest
Published: May 15, 2022 License: Apache-2.0 Imports: 25 Imported by: 4

README

service

Basic Service Functionality

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Config

func Config(i interface{}) chan struct{}

func Crud

func Crud[T any](opts *CrudOpts)

func CtxDB

func CtxDB(c context.Context) (*gorm.DB, error)

func CtxDb

func CtxDb(c context.Context) (db *gorm.DB, close func(), err error)

func CtxDone

func CtxDone(c context.Context) func()

func CtxErr

func CtxErr(c context.Context, err error) bool

func CtxReq

func CtxReq(c context.Context) *http.Request

func CtxRes

func CtxSessionID

func CtxSessionID(c context.Context) string

func CtxTenant

func CtxTenant(c context.Context) string

func CtxVars

func CtxVars(c context.Context) map[string]string

func DB

func DB() (ret *gorm.DB, err error)

func DBClose

func DBClose(n string) error

func DBCloseAll

func DBCloseAll()

func DBN

func DBN(n string) (ret *gorm.DB, err error)

func DataDel

func DataDel(k string) (int64, error)

func DataGet

func DataGet(k string) (string, error)

func DataHDel

func DataHDel(k string, v ...string) (int64, error)

func DataHGet

func DataHGet(k string, v string) (string, error)

func DataHGetAll

func DataHGetAll(k string) (map[string]string, error)

func DataHSet

func DataHSet(k string, v ...interface{}) (int64, error)

func DataSet

func DataSet(k string, v interface{}, to int) error

func Debug

func Debug(s string, p ...interface{})

func Dec

func Dec(in []byte) (out []byte, err error)

TODO: Implement this

func Dequeue

func Dequeue(q string, to int) ([]string, error)

func Enc

func Enc(in []byte) (out []byte, err error)

TODO: Implement this

func Enqueue

func Enqueue(q string, v ...interface{}) error

func Err

func Err(err error)

func Fatal

func Fatal(s ...interface{})

func Hash

func Hash(in []byte) (out []byte, err error)

TODO: Implement this

func HttpHandle

func HttpHandle[TIN, TOUT any](hpath string, method string, perm PermDef, f func(context.Context, TIN) (TOUT, error))

func HttpRouter

func HttpRouter() *mux.Router

func HttpRun

func HttpRun(addr string)

func HttpStart

func HttpStart(addr string) *http.Server

func HttpStop

func HttpStop()

func Init

func Init(s string)

func IsDocker

func IsDocker() bool

func LockMainRoutine

func LockMainRoutine()

func Log

func Log(s string, p ...interface{})

func OnStop

func OnStop(f func())

func Pub

func Pub(ch string, msg interface{})

func QRpc

func QRpc(q string, i interface{}, o interface{}) error

func QSend

func QSend(q string, i interface{}) error

func QServe

func QServe(q string, f func(i interface{}) (o interface{}, err error))

func ServerTiming

func ServerTiming(w http.ResponseWriter, metric string, desc string, t time.Time)

func SessionDec

func SessionDec(s string) (t string, id string, hash []byte, err error)

func SessionDel

func SessionDel(rawid string) (ret int64, err error)

func SessionEnc

func SessionEnc(s *Session) (id string, sessbs []byte)

func SessionSave

func SessionSave(s *Session) (id string, err error)

func Sub

func Sub(ch ...string) (ret <-chan *Msg, closefn func())

Types

type ApiEntry

type ApiEntry struct {
	Path   string
	Method string
	Perm   PermDef
	In     interface{}
	Out    interface{}
}

type CookieName

type CookieName string
const (
	COOKIE_SESSION CookieName = "SESSIONID"
	COOKIE_TENANT  CookieName = "TENANTID"
)

type CrudOpts

type CrudOpts struct {
	Name        string
	Ops         string
	DefaultPerm string
	CPerm       string
	RPerm       string
	UPerm       string
	DPerm       string
}

func (*CrudOpts) PermFor

func (c *CrudOpts) PermFor(op string) string

type CtxKey

type CtxKey string
const (
	CTX_REQ     CtxKey = "REQ"
	CTX_RES     CtxKey = "RES"
	CTX_DONE    CtxKey = "DONE"
	CTX_ID      CtxKey = "ID"
	CTX_START   CtxKey = "START"
	CTX_SESSION CtxKey = "SESSION"
)

type EMPTY_TYPE

type EMPTY_TYPE struct{}

type HeaderName

type HeaderName string
const (
	HEADER_APIKEY HeaderName = "X-APIKEY"
	HEADER_TENAT  HeaderName = "X-TENANT"
)

type LoginRequest

type LoginRequest struct {
	Tenant   string `json:"tenant"`
	Username string `json:"username"`
	Password string `json:"password"`
}

type LoginResponse

type LoginResponse struct {
}

type Msg

type Msg struct {
	Chan    string
	Payload string
	Err     error
}

type PermDef

type PermDef string
const (
	PERM_ALL  PermDef = ""
	PERM_AUTH PermDef = "+"
	PERM_ROOT PermDef = "*"
)

type SecGroup

type SecGroup struct {
	VO
	Name  string     `json:"name"`
	Perms []*SecPerm `json:"perms" gorm:"many2many:sec_group_perms;"`
}

type SecPerm

type SecPerm struct {
	VO
	Name string `json:"name"`
	Val  string `json:"val"`
}

type SecUser

type SecUser struct {
	VO
	Username string      `json:"username"`
	Email    string      `json:"email"`
	Hash     string      `json:"-"`
	Tenant   string      `json:"tenant"`
	Enabled  *bool       `json:"enabled"`
	Groups   []*SecGroup `json:"groups" gorm:"many2many:sec_user_groups;"`
}

type Session

type Session struct {
	Username  string             `json:"username"`
	Sessionid string             `json:"sessionid"`
	Perms     map[PermDef]string `json:"perms"`
	Tenant    string             `json:"tenant"`
	CreatedAt time.Time          `json:"created_at"`
	Hash      []byte             `json:"-"`
}

func CtxSession

func CtxSession(c context.Context) *Session

func SessionLoad

func SessionLoad(rawid string) (sess *Session, err error)

type VO

type VO struct {
	ID uint64 `json:"id"`
}

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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