Documentation
¶
Index ¶
- Constants
- Variables
- func AddMetaDataTags(ws *restful.WebService, tags []string)
- func AddMetaDataTagsAndWriteSample(ws *restful.WebService, tags []string, entityType interface{})
- func AddWriteSample(ws *restful.WebService, entityType interface{})
- func CloseAllDB() error
- func Copy(target interface{}, from interface{})
- func DB() (*gorm.DB, error)
- func DBs() ([]*gorm.DB, error)
- func EnvIsProd() bool
- func ExecSQLFile(fileName string) error
- func Migrate(assetNames []string, afn bindata.AssetFunc, dbURL, dialect string) error
- func NewAPIError(code int, msg, desc string) *apierrors.APIError
- func PageQueryParams(req *restful.Request) (pageIndex, pageSize uint)
- func RedisClient() *redis.Client
- func RedisClusterClient() *redis.ClusterClient
- func Serve(svc []*restful.WebService)
- func ServeRestful()
- func Validate() *validator.Validate
- func ValidateEntity(entity interface{}) error
- func ValidateEntityAndWriteResp(res *restful.Response, entity interface{}, apiErr *apierrors.APIError) error
- func ValidateTranslator() ut.Translator
- type BaseController
- type BaseDO
- type BaseDTO
- type BaseResource
- type ComplexBaseDO
- type EmptyRespEntity
- type Entity
- type JSONDate
- type JSONTime
- type MultiDBSource
- type Page
- type PageDTO
- type Pageable
- type Pagination
- type RespEntity
- type Response
- type ResponseEntitySample
- type SampleBaseDO
- type Sort
Constants ¶
const ( //EnvPgTestDataFile import test data sql file EnvPgTestDataFile = "PG_TEST_DATA_FILE" //AppRunEnvLocal app run env "local" AppRunEnvLocal = "local" //AppRunEnvTest app run env "test" AppRunEnvTest = "test" //AppRunEnvProd app run env "prod" AppRunEnvProd = "prod" )
const ( //SortDirectionDESC 降序 SortDirectionDESC = "DESC" //SortDirectionASC 升序 SortDirectionASC = "ASC" )
const ( //PageIndexKey pagination page index default 0 PageIndexKey = "page_index" //DefaultPageIndexValue pagination page index default 0 DefaultPageIndexValue = 0 //PageSizeKey pagination page size default 10 PageSizeKey = "page_size" //DefaultPageSizeValue pagination page size default 10 DefaultPageSizeValue = 10 )
const KeyOpenAPITags = restfulSpec.KeyOpenAPITags
KeyOpenAPITags is a Metadata key for a restful Route
Variables ¶
var ErrIDInvalid = NewAPIError(100001, "非法ID", "ID为数值且不能为0")
ErrIDInvalid REST resource ID invalid
var (
ErrNoDatabaseConfiguration = errors.New("there isn't any database setting in the configuration file")
)
var ErrPageParamsInvalid = NewAPIError(100002, "分页参数有误", "page_index,page_size为数值类型,page_size 大于5小于100 被5整除")
ErrPageParamsInvalid Pagination params invalid
Functions ¶
func AddMetaDataTags ¶
func AddMetaDataTags(ws *restful.WebService, tags []string)
AddMetaDataTags add metadata tags to Webservice all routes
func AddMetaDataTagsAndWriteSample ¶
func AddMetaDataTagsAndWriteSample(ws *restful.WebService, tags []string, entityType interface{})
AddMetaDataTagsAndWriteSample AddMetaDataTags() and WriteSample
func AddWriteSample ¶
func AddWriteSample(ws *restful.WebService, entityType interface{})
AddWriteSample setting a webservice all routes to write sample with ResponseEntity
func Copy ¶
func Copy(target interface{}, from interface{})
Copy copy anything. just proxy to copier(jinzhu/copier).
func EnvIsProd ¶
func EnvIsProd() bool
EnvIsProd check env is production ? local and test will drop database & import test data
func ExecSQLFile ¶
ExecSQLFile danger!!! just for importing test data.
func NewAPIError ¶
NewAPIError new api error
func PageQueryParams ¶
func PageQueryParams(req *restful.Request) (pageIndex, pageSize uint)
PageQueryParams get page params from request
func RedisClient ¶
func RedisClient() *redis.Client
RedisClient get redis client return for simple or sentinel(failover)mode
func RedisClusterClient ¶
func RedisClusterClient() *redis.ClusterClient
RedisClusterClient redis cluster client
func ServeRestful ¶
func ServeRestful()
func ValidateEntityAndWriteResp ¶
func ValidateEntityAndWriteResp(res *restful.Response, entity interface{}, apiErr *apierrors.APIError) error
ValidateEntityAndWriteResp validate entity and write header and error as entity
Types ¶
type BaseController ¶
type BaseController struct { }
BaseController has some basic methods
func (BaseController) ValidatePageableParams ¶
func (bc BaseController) ValidatePageableParams(req *restful.Request, res *restful.Response) (pageable *Pageable, ok bool)
ValidatePageableParams validate pagination params return paable struct
func (BaseController) ValidateResourceID ¶
func (bc BaseController) ValidateResourceID(req *restful.Request, res *restful.Response, IDKey string) (ID uint, ok bool)
ValidateResourceID validate REST resource ID in pathparam and return it if validated.
type BaseDO ¶
type BaseDO struct { ID uint `gorm:"primary_key" json:"id"` // primary key CreatedAt time.Time `json:"created_at,omitempty"` // created time UpdatedAt time.Time `json:"updated_at,omitempty"` //updated time DeletedAt *time.Time `sql:"index" json:"deleted_at,omitempty"` //deleted time }
Model gorm model
type BaseDTO ¶
type BaseDTO struct { ID uint `json:"id,omitempty" description:"资源ID"` CreatedAt JSONTime `json:"created_at,omitempty" description:"创建日期"` UpdatedAt JSONTime `json:"updated_at,omitempty" description:"更新日期"` }
BaseDTO Data Transfer Object
type BaseResource ¶
type BaseResource struct {
BaseController
}
BaseResource RESTFul webservice name ,alias BaseController.
type ComplexBaseDO ¶
type ComplexBaseDO struct { BaseDO Version uint `json:"version"` //version opt lock Addition string `json:"addition,omitempty"` }
ComplexBaseDO gorm model composed Model add Addition
type MultiDBSource ¶
type MultiDBSource struct {
// contains filtered or unexported fields
}
type Page ¶
type Page struct { List interface{} `json:"list,omitempty"` Total uint `json:"total,omitempty"` Offset uint `json:"offset,omitempty"` Index uint `json:"page_index,omitempty"` Size uint `json:"page_size,omitempty"` Pages uint `json:"pages,omitempty"` }
Page page
type PageDTO ¶
type PageDTO struct { Total uint `json:"total"` Index uint `json:"page_index"` Size uint `json:"page_size"` Pages uint `json:"pages"` }
PageDTO common page struct
type Pagination ¶
type Pagination struct { Offset uint `json:"offset,omitempty"` Limit uint `json:"limit,omitempty"` Condition interface{} `json:"condition,omitempty"` }
Pagination 新建分页查询
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response rest response
func RestResponse ¶
type ResponseEntitySample ¶
type ResponseEntitySample struct { ErrCode int `json:"err_code,omitempty"` ErrMsg string `json:"err_msg,omitempty"` ErrDesc string `json:"err_desc,omitempty"` Data interface{} `json:"data,omitempty"` }
ResponseEntity response entity for go-restful Writes(ResponseEntity{Data: Type{}})
func NewWriteSample ¶
func NewWriteSample(entity interface{}) ResponseEntitySample
NewWriteSample new write sample
type SampleBaseDO ¶
type SampleBaseDO struct {
ID uint `gorm:"primary_key" json:"id"`
}
SampleBaseDO model with id pk