util

package
v2.0.0-...-0229899 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ERRMSG = "errMsg"
	//參數錯誤
	PARAM  = "parameter"
	FORMAT = "format"
	INT    = "int"
)

-------------------------------// error type

View Source
const (
	REASON  = "reason"
	SUCCESS = "success"
	FAILED  = "failed"
)

成功與否

View Source
const (
	COMMA  = "comma"
	PERIOD = "period"
	SPACE  = " "
)

標點符號

View Source
const (
	CREATE = "create"
	UPDATE = "update"
	MODIFY = "modify"
	GET    = "get"
	DELETE = "delete"
	APPEND = "append"
	REMOVE = "remove"
)

CRUD 方法

View Source
const (
	MODULE = "module"
)

模組

Variables

This section is empty.

Functions

func GetI18nData

func GetI18nData(c *gin.Context) gogo_i18n.GoGoi18nInterface

func LoadI18nDataFromDatabase

func LoadI18nDataFromDatabase(db *gorm.DB, storeType string, storePath string)

func Pagination

func Pagination(data map[string]interface{}) func(in *gorm.DB) *gorm.DB
func Pagination(in *gorm.DB, data map[string]interface{}) (*gorm.DB, map[string]interface{}) {
	if data == nil {
		return in, data
	} else if data[pagination.PAGE_SIZE] == nil && data[pagination.PAGE] == nil {
		return in, data
	} else {
		var (
			pageSize = 10
			page     = 1
		)

		if in := data[pagination.PAGE_SIZE]; in != nil {
			pageSize, _ = strconv.Atoi(in.(string))
			delete(data, pagination.PAGE_SIZE)
		}
		if in := data[pagination.PAGE]; in != nil {
			page, _ = strconv.Atoi(in.(string))
			delete(data, pagination.PAGE)
		}
		return in.Limit(pageSize).Offset((page - 1) * pageSize), data
	}
}

func TotalSize

func TotalSize(in *gorm.DB) int

Types

type HttpTester

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

func (*HttpTester) DELETE

func (h *HttpTester) DELETE(uri string, param interface{}) (int, *e.Response)

DELETE 模擬 Delete Request的動作

func (*HttpTester) GET

func (h *HttpTester) GET(uri string) (int, *e.Response)

Get 模擬Get Request的動作

func (*HttpTester) PATCH

func (h *HttpTester) PATCH(uri string, param interface{}) (int, *e.Response)

PATCH 模擬 Patch Request的動作

func (*HttpTester) POST

func (h *HttpTester) POST(uri string, param interface{}) (int, *e.Response)

POST 模擬Post Request的動作

func (*HttpTester) POST_FORM

func (h *HttpTester) POST_FORM(uri string, param interface{}) (int, *e.Response)

POST_FORM 模擬Post Request的動作

func (*HttpTester) PUT

func (h *HttpTester) PUT(uri string, param interface{}) (int, *e.Response)

PUT 模擬Post Request的動作

type HttpTesterInterface

type HttpTesterInterface interface {
	GET(uri string) (int, *e.Response)
	POST(uri string, param interface{}) (int, *e.Response)
	POST_FORM(uri string, param interface{}) (int, *e.Response)
	PUT(uri string, param interface{}) (int, *e.Response)
	PATCH(uri string, param interface{}) (int, *e.Response)
	DELETE(uri string, param interface{}) (int, *e.Response)
}

func NewHttpTester

func NewHttpTester(router *gin.Engine) HttpTesterInterface

type I18nMsg

type I18nMsg struct {
	Module string
	Core   gogo_i18n.GoGoi18nInterface
}

func NewI18nMsg

func NewI18nMsg(module string) *I18nMsg

func (*I18nMsg) Append

func (i *I18nMsg) Append(isSuccess bool, module string, data map[string]interface{}) string

func (*I18nMsg) Create

func (i *I18nMsg) Create(isSuccess bool, data map[string]interface{}) string

func (*I18nMsg) Delete

func (i *I18nMsg) Delete(isSuccess bool, data map[string]interface{}) string

func (*I18nMsg) Get

func (i *I18nMsg) Get(isSuccess bool, data map[string]interface{}) string

func (*I18nMsg) GetModule

func (i *I18nMsg) GetModule(name string) string

func (*I18nMsg) Modify

func (i *I18nMsg) Modify(isSuccess bool, data map[string]interface{}) string

func (*I18nMsg) ParamFormatError

func (i *I18nMsg) ParamFormatError(data map[string]interface{}) string

func (*I18nMsg) ParamIntError

func (i *I18nMsg) ParamIntError(data map[string]interface{}) string

func (*I18nMsg) ParamRequiredError

func (i *I18nMsg) ParamRequiredError(data map[string]interface{}) string

func (*I18nMsg) Remove

func (i *I18nMsg) Remove(isSuccess bool, module string, data map[string]interface{}) string

func (*I18nMsg) SetCore

func (i *I18nMsg) SetCore(data gogo_i18n.GoGoi18nInterface)

func (*I18nMsg) SetModule

func (i *I18nMsg) SetModule(module string) *I18nMsg

func (*I18nMsg) Update

func (i *I18nMsg) Update(isSuccess bool, data map[string]interface{}) string

type I18nMsgContent

type I18nMsgContent struct {
	Data  string `json:"data"`
	Error string `json:"error"`
}

type I18nMsgInterface

type I18nMsgInterface interface {
	//基本方法
	SetCore(data gogo_i18n.GoGoi18nInterface)
	SetModule(module string) *I18nMsg
	//error handler
	ParamFormatError(data map[string]interface{}) string
	ParamIntError(data map[string]interface{}) string
	ParamRequiredError(data map[string]interface{}) string
	//取得模組
	GetModule(name string) string
	//http方法
	Get(isSuccess bool, data map[string]interface{}) string
	Create(isSuccess bool, data map[string]interface{}) string
	Update(isSuccess bool, data map[string]interface{}) string
	Modify(isSuccess bool, data map[string]interface{}) string
	Delete(isSuccess bool, data map[string]interface{}) string
	Append(isSuccess bool, module string, data map[string]interface{}) string
	Remove(isSuccess bool, module string, data map[string]interface{}) string
}

type PaginationData

type PaginationData struct {
	Total int         `json:"total"`
	Data  interface{} `json:"data"`
}

func NewPaginationData

func NewPaginationData(total int, data interface{}) *PaginationData

type RequestHandler

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

func (*RequestHandler) BindBody

func (r *RequestHandler) BindBody(c *gin.Context, body interface{}) error

BindBody : 綁定 body

func (*RequestHandler) ValidValidation

func (r *RequestHandler) ValidValidation(v *validation.Validation) error

ValidValidation : 驗證表單資訊

type RequestHandlerInterface

type RequestHandlerInterface interface {
	//BindBody : 綁定 body
	BindBody(c *gin.Context, body interface{}) error
	//ValidValidation : 驗證表單資訊
	ValidValidation(v *validation.Validation) error
}

func NewRequestHandler

func NewRequestHandler() RequestHandlerInterface

type Requester

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

func (*Requester) DELETE

func (r *Requester) DELETE(uri string, param interface{}) (*e.Response, error)

func (*Requester) DeleteWithHeader

func (r *Requester) DeleteWithHeader(uri string, header map[string]string, param interface{}) (*e.Response, error)

func (*Requester) GET

func (r *Requester) GET(uri string) (*e.Response, error)

func (*Requester) GetWithHeader

func (r *Requester) GetWithHeader(uri string, header map[string]string) (*e.Response, error)

func (*Requester) PATCH

func (r *Requester) PATCH(uri string, param interface{}) (*e.Response, error)

func (*Requester) POST

func (r *Requester) POST(uri string, param interface{}) (*e.Response, error)

func (*Requester) PUT

func (r *Requester) PUT(uri string, param interface{}) (*e.Response, error)

func (*Requester) PatchWithHeader

func (r *Requester) PatchWithHeader(uri string, header map[string]string, param interface{}) (*e.Response, error)

func (*Requester) PostWithHeader

func (r *Requester) PostWithHeader(uri string, header map[string]string, param interface{}) (*e.Response, error)

func (*Requester) PutWithHeader

func (r *Requester) PutWithHeader(uri string, header map[string]string, param interface{}) (*e.Response, error)

func (*Requester) ReadJSONResponse

func (r *Requester) ReadJSONResponse(in *http.Response) (*e.Response, error)

type RequesterInterface

type RequesterInterface interface {
	GET(uri string) (*e.Response, error)
	POST(uri string, param interface{}) (*e.Response, error)
	PUT(uri string, param interface{}) (*e.Response, error)
	PATCH(uri string, param interface{}) (*e.Response, error)
	DELETE(uri string, param interface{}) (*e.Response, error)
	GetWithHeader(uri string, header map[string]string) (*e.Response, error)
	PostWithHeader(uri string, header map[string]string, param interface{}) (*e.Response, error)
	PutWithHeader(uri string, header map[string]string, param interface{}) (*e.Response, error)
	PatchWithHeader(uri string, header map[string]string, param interface{}) (*e.Response, error)
	DeleteWithHeader(uri string, header map[string]string, param interface{}) (*e.Response, error)
}

func NewRequester

func NewRequester(client *http.Client) RequesterInterface

Jump to

Keyboard shortcuts

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