common

package
v0.41.10 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddOneItem

func AddOneItem[T any](r *http.Request, cache *core.Cache, model *T)

func DeleteOneItem

func DeleteOneItem[T any](r *http.Request, cache *core.Cache, model *T)

func GetAllItems

func GetAllItems[T any](r *http.Request, cache *core.Cache, model T, subsystem string)

func GetOneItem

func GetOneItem[T any](r *http.Request, cache *core.Cache, model T, subsystem string)

func UnmarshalRequestData

func UnmarshalRequestData[T any](r *http.Request, model *T) error

func UpdateOneItem

func UpdateOneItem[T any](r *http.Request, cache *core.Cache, model *T)

func WriteResponse added in v0.41.0

func WriteResponse(w http.ResponseWriter, resp interface{}, code int) error

Types

type Logger

type Logger struct {
	// CallerID is a nickname of the user calling the API.
	CallerID string `json:"-"`

	// Code integer is a HTTP return code.
	Code int `json:"code" validation:"required"`

	// IPAddress string is basically an user's IPv4/IPv6 address (beware of proxies).
	IPAddress string `json:"-"`

	// Message string holds a custom message returned by a various HTTP handler.
	Message string `json:"message" validation:"required"`

	// Method string hold a HTTP method name.
	Method string `json:"method"`

	// Route string is the very route called by user.
	Route string `json:"route"`

	// Time property hold the actual time of the request processing.
	Time time.Time `json:"time" validation:"required"`

	// Version is the tagged version of the client's SW (compiled in).
	Version string `json:"version"`

	// WorkerName string is the name of a worker processing such request.
	WorkerName string `json:"worker_name" validation:"required"`
}

func NewLogger

func NewLogger(r *http.Request, worker string) *Logger

func (*Logger) Println

func (l *Logger) Println(msg string, code int) bool

Println formats the encoded Logger struct into an output string to stdin.

type Response

type Response struct {
	AuthGranted bool `json:"auth_granted" default:false`
	Code        int  `json:"code"`

	PublicKey string `json:"public_key,omitempty"`
	Key       string `json:"key,omitempty"`
	Message   string `json:"message"`
	Count     int    `json:"count,omitempty"`

	Subscription struct {
		Replies  bool `json:"replies"`
		Mentions bool `json:"mentions"`
	} `json:"subscription,omitempty"`
	Devices []models.Device `json:"devices,omitempty"`

	Polls    map[string]models.Poll `json:"polls,omitempty"`
	Posts    map[string]models.Post `json:"posts,omitempty"`
	Users    map[string]models.User `json:"users,omitempty"`
	FlowList []string               `json:"flow_records,omitempty"`

	Data []byte `json:"data,omitempty"`

	// very stats properties
	FlowStats map[string]int             `json:"flow_stats,omitempty"`
	UserStats map[string]models.UserStat `json:"user_stats,omitempty"`

	// auth tokens (JWT)
	AccessToken  string `json:"access_token,omitempty"`
	RefreshToken string `json:"refresh_token,omitempty"`
}

func (*Response) Write

func (r *Response) Write(w http.ResponseWriter) error

func (*Response) WritePix

func (r *Response) WritePix(w http.ResponseWriter) error

type ServiceOpts

type ServiceOpts struct {
	Request *http.Request

	Polls bool
	Posts bool
	Stats bool
	Users bool
}

Jump to

Keyboard shortcuts

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