gincrud

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

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

Go to latest
Published: Jan 19, 2023 License: MIT Imports: 11 Imported by: 0

README

gincrud

Crud utilities for gin

Documentation

Index

Constants

View Source
const (
	FORM_CONTENT = "form"
	JSON_CONTENT = "json"
	XML_CONTENT  = "xml"
)

Variables

This section is empty.

Functions

func Decode

func Decode(c *gin.Context, obj interface{}) error

func Delete

func Delete(key, bucket string, store gostore.ObjectStore, c *gin.Context, onSuccess OnSuccess, onError OnError)

func Get

func Get(key, bucket string, store gostore.ObjectStore, c *gin.Context, record interface{},
	unMarshalFn UnMarshalFn, onSuccess OnSuccess, onError OnError)

func GetAll

func GetAll(bucket string, store gostore.ObjectStore, c *gin.Context, unMarshalFn UnMarshalFn, onSuccess OnSuccess, onError OnError)

TODO: Extract core logic from each crud function i.e make doGetAll, doGet, ... they return data, err

func GetFunctionName

func GetFunctionName(i interface{}) string

func Post

func Post(bucket string, store gostore.ObjectStore, c *gin.Context,
	record interface{}, fn GetKey, marshalFn MarshalFn, onSuccess OnSuccess, onError OnError)

func Put

func Put(key, bucket string, store gostore.ObjectStore, c *gin.Context, record interface{},
	marshalFn MarshalFn, onSuccess OnSuccess, onError OnError)

Types

type ChangeResult

type ChangeResult struct {
	Old map[string]interface{}
	New map[string]interface{}
}

type CreateResult

type CreateResult struct {
	New map[string]interface{}
}

type ErrorCtx

type ErrorCtx struct {
	Bucket string

	GinCtx *gin.Context
	// contains filtered or unexported fields
}

type ErrorList

type ErrorList struct {
	Msg   string                 `json:"msg"`
	Error map[string]interface{} `json:"error"`
}

type GetKey

type GetKey func(interface{}, *gin.Context) string

Get unique key from object and request

type InvalidContent

type InvalidContent struct {
	S           string `json:"msg"`
	ContentType string
}

func (InvalidContent) Error

func (e InvalidContent) Error() string

type JSONError

type JSONError interface {
	Serialize() map[string]interface{} //serialize error to json
}

type MarshalError

type MarshalError struct {
	Data map[string]interface{}
}

type MarshalFn

type MarshalFn func(ctx *gin.Context, opts interface{}) (interface{}, error)

Convert request json data to data and map, you can handle validation here

type OnError

type OnError func(ctx interface{}, err error) error

Called when a crud operation fails

type OnSuccess

type OnSuccess func(ctx SuccessCtx) (string, error)

Called when a crud operation is successful

type ParsedContent

type ParsedContent map[string]interface{}

type Results

type Results struct {
	Data       []map[string]interface{} `json:"data"`
	Count      int                      `json:"count,omitempty"`
	TotalCount uint64                   `json:"total_count,omitempty"`
}

type SuccessCtx

type SuccessCtx struct {
	Bucket   string
	Key      string
	Existing map[string]interface{}
	Result   map[string]interface{}
	GinCtx   *gin.Context
}

type UnMarshalFn

type UnMarshalFn func(*gin.Context, string, map[string]interface{}, interface{}) (map[string]interface{}, error)

type UnknownContent

type UnknownContent struct {
	S           string `json:"msg"`
	ContentType string `json:"content-type"`
}

func (UnknownContent) Error

func (e UnknownContent) Error() string

Jump to

Keyboard shortcuts

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