kitty

package module
v0.0.0-...-2f0169a Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DebugMode indicates kitty mode is debug.
	DebugMode = "debug"
	// ReleaseMode indicates kitty mode is release.
	ReleaseMode = "release"
	// TestMode indicates kitty mode is test.
	TestMode = "test"
)
View Source
const EnvKittyMode = "KITTY_MODE"

EnvKittyMode indicates environment name for kitty mode.

Variables

This section is empty.

Functions

func DereferenceInterface

func DereferenceInterface(v interface{}) interface{}

DereferenceInterface ...

func DereferenceType

func DereferenceType(t reflect.Type) reflect.Type

DereferenceType dereference, get the underlying non-pointer type.

func DereferenceValue

func DereferenceValue(v reflect.Value) reflect.Value

DereferenceValue dereference and unpack interface, get the underlying non-pointer and non-interface value.

func Eval

func Eval(s *Structs, db *gorm.DB, f *structs.Field, exp string) error

Eval for test

func FormatQryField

func FormatQryField(field *structs.Field) string

FormatQryField for test

func GetSub

func GetSub(s string, sub string) string

GetSub 获得tag标签段

func Getter

func Getter(s *Structs, param map[string]interface{}, db *gorm.DB, c Context) error

Getter before execute

func HasRegister

func HasRegister(name string) bool

HasRegister .

func RegisterFunc

func RegisterFunc(name string, func1 govaluate.ExpressionFunction)

RegisterFunc ...

func RegisterType

func RegisterType(v interface{})

RegisterType 注册模型

func SetMode

func SetMode(value string)

SetMode sets kitty mode according to input string.

func Setter

func Setter(s *Structs, param map[string]interface{}, db *gorm.DB, c Context) error

Setter after execute successful

func ToCamel

func ToCamel(s string) string

ToCamel 对id的特别处理。 PayID UserID 。

Types

type API

type API struct {
	Form   url.Values
	Crud   CRUDInterface
	Ctx    Context
	Params map[string]interface{}
}

API for web api

func (*API) CallRPC

func (c *API) CallRPC() (interface{}, error)

CallRPC .

func (*API) Create

func (c *API) Create() (interface{}, error)

Create ...

func (*API) List

func (c *API) List() (interface{}, error)

List 。

func (*API) One

func (c *API) One() (interface{}, error)

One 单条记录

func (*API) Update

func (c *API) Update() (interface{}, error)

Update ...

type CRUDInterface

type CRUDInterface interface {
	Do(*SearchCondition, string, Context) (interface{}, error)
}

CRUDInterface ...

type Context

type Context interface {
	CurrentUID() (string, error)
	GetCtxInfo(string) (interface{}, error)
}

Context 获取登录信息

type CrudResult

type CrudResult struct {
	Code    int         `json:"code"`
	Data    interface{} `json:"data,omitempty"`
	Count   *int        `json:"count,omitempty"`
	Message string      `json:"message,omitempty"`
	Ref     int64       `json:"ref,omitempty"`
}

CrudResult 结果

type FieldTypeAndKind

type FieldTypeAndKind struct {
	ModelName   string       //模型名称
	KindOfField reflect.Kind //类型  struct
	TypeOfField reflect.Type //类型
	// contains filtered or unexported fields
}

FieldTypeAndKind 字段类型,模型名称

func TypeKind

func TypeKind(field *structs.Field) FieldTypeAndKind

TypeKind 。。。

func (FieldTypeAndKind) Create

func (f FieldTypeAndKind) Create() *Structs

Create ..

type KK

type KK struct {
	Error error
	// contains filtered or unexported fields
}

func New

func New(db *gorm.DB) *KK

func (*KK) And

func (kk *KK) And(q *QueryParam) *KK

func (*KK) GormQueryExpr

func (kk *KK) GormQueryExpr(expr interface{}) interface{}

func (*KK) Join

func (kk *KK) Join(model interface{}, on *OnJoin) *KK

func (*KK) LeftJoin

func (kk *KK) LeftJoin(model interface{}, on *OnJoin) *KK

func (*KK) Model

func (kk *KK) Model(value interface{}) *KK

rds的src不是gorm模型,并且rds的查询参数不是gorm表达式

func (*KK) Or

func (kk *KK) Or(q *QueryParam) *KK

func (*KK) Order

func (kk *KK) Order(value interface{}, reorder ...bool) *KK

func (*KK) Page

func (kk *KK) Page(page *Page) *KK

func (*KK) Rds

func (kk *KK) Rds(args ...interface{}) *KK

kk.Model().Select().Rds(&field,"id=?",user.id) kk.Select("Count(*)").Rds(&field) kk.Select("Sum(money)").Rds(&field) kk.Page().Rds(&field,kk.GormQueryExpr())

func (*KK) RightJoin

func (kk *KK) RightJoin(model interface{}, on *OnJoin) *KK

func (*KK) Select

func (kk *KK) Select(value interface{}) *KK

count(*) sum(xxx) average(xxx) date_format field1,field2

func (*KK) Set

func (kk *KK) Set(dst, given interface{}) *KK

func (*KK) Verify

func (kk *KK) Verify(success bool, err string) *KK

func (*KK) Where

func (kk *KK) Where(q *QueryParam) *KK

type LocalCrud

type LocalCrud struct {
	Model  string // RPC 最终会调用此,所以只能用model作为参数。
	Strs   *Structs
	DB     *gorm.DB
	Callbk SuccessCallback
	RPC    RPC
}

LocalCrud 本地操作

func (*LocalCrud) Do

func (local *LocalCrud) Do(search *SearchCondition, action string, c Context) (interface{}, error)

Do 本地执行db操作

type OnJoin

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

func On

func On(key, joinKey string, joinModel interface{}) *OnJoin

func (*OnJoin) And

func (on *OnJoin) And(q *QueryParam) *OnJoin

func (*OnJoin) ON

func (on *OnJoin) ON(joinName string, db *gorm.DB) (string, []interface{})

type Page

type Page struct {
	Page    uint32 `json:"page"`
	Limit   uint32 `json:"limit"`
	PageMax uint32 `json:"page_max"`
	Total   uint32 `json:"total"`
}

Page 分页

func MakePage

func MakePage(page uint32, limit uint32, total uint32) Page

MakePage .

func (*Page) CountPages

func (p *Page) CountPages(total uint32)

CountPages .

func (*Page) GetOffset

func (p *Page) GetOffset() uint32

GetOffset .

type QueryParam

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

func Param

func Param(model interface{}, field string, values ...interface{}) *QueryParam

func (*QueryParam) AND

func (q *QueryParam) AND(model interface{}, field string, values ...interface{}) *QueryParam

func (*QueryParam) And

func (q *QueryParam) And(field string, values ...interface{}) *QueryParam

func (*QueryParam) OR

func (q *QueryParam) OR(model interface{}, field string, values ...interface{}) *QueryParam

func (*QueryParam) Or

func (q *QueryParam) Or(field string, values ...interface{}) *QueryParam

type RPC

type RPC interface {
	Call(*SearchCondition, string, Context) (interface{}, error)
	WebCall(*Structs, *SearchCondition, Context) error
}

RPC rpc call

type RPCCrud

type RPCCrud struct {
	RPC RPC
}

RPCCrud remote call

func (*RPCCrud) Do

func (crud *RPCCrud) Do(search *SearchCondition, action string, c Context) (interface{}, error)

Do 调用rpc远程执行

type Resource

type Resource struct {
	Model     interface{}
	ModelName string
	Strs      *Structs
}

Resource ....

func NewResource

func NewResource(m interface{}) *Resource

NewResource ...

type Result

type Result struct {
	CrudResult
	NameAs map[string][]string `json:"-"`
	Cfg    jsoniter.API
}

Result 。

func (*Result) JsonAPI

func (c *Result) JsonAPI(j jsoniter.API)

JsonAPI 可以由外部提供jsonapi

func (*Result) MarshalJSON

func (c *Result) MarshalJSON() ([]byte, error)

MarshalJSON ...

type SearchCondition

type SearchCondition struct {
	FormValues  map[string][]string    `json:"form_values,omitempty"`
	Page        *Page                  `json:"page,omitempty"`
	ReturnCount int                    `json:"return_count,omitempty"`
	Params      map[string]interface{} `json:"params,omitempty"`
}

SearchCondition ...

type StructFieldInfo

type StructFieldInfo struct {
	TypeKind              FieldTypeAndKind
	ForeignKey            string //外键
	AssociationForeignkey string //关联外键
	Relationship          string //belongs_to has_one has_many
}

StructFieldInfo 结构体信息

type Structs

type Structs struct {
	*structs.Struct
	// contains filtered or unexported fields
}

Structs .

func CreateModel

func CreateModel(name string) *Structs

CreateModel 通过名称创建模型

func CreateModelStructs

func CreateModelStructs(v interface{}) *Structs

CreateModelStructs ...

func (*Structs) CallMethod

func (s *Structs) CallMethod(name string, values ...reflect.Value) []reflect.Value

CallMethod .

func (*Structs) Copy

func (s *Structs) Copy(src *Structs)

Copy Structs

func (*Structs) GetRelationsWithModel

func (s *Structs) GetRelationsWithModel(fieldname string, modelName string) (fi StructFieldInfo, err error)

GetRelationsWithModel fieldname (elem) must struct -> email = user

func (*Structs) New

func (s *Structs) New() *Structs

New a obj

func (*Structs) ParseFormValues

func (s *Structs) ParseFormValues(values url.Values) error

ParseFormValues form_value -> struct

func (*Structs) Raw

func (s *Structs) Raw() interface{}

Raw return obj

func (*Structs) SetFieldValue

func (s *Structs) SetFieldValue(f *structs.Field, value interface{}) error

SetFieldValue ...

func (*Structs) SetValue

func (s *Structs) SetValue(values map[string]interface{}) error

SetValue ...key 参数为蛇形 入 name_of_who

type SuccessCallback

type SuccessCallback func(*Structs, *gorm.DB) error

SuccessCallback 执行成功后,回调。返回error后,回滚事务

type TimeAsString

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

TimeAsString format time.Time as string

func (*TimeAsString) Decode

func (codec *TimeAsString) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator)

Decode string to time.Time

func (*TimeAsString) Encode

func (codec *TimeAsString) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream)

Encode time.Time to string

func (*TimeAsString) IsEmpty

func (codec *TimeAsString) IsEmpty(ptr unsafe.Pointer) bool

IsEmpty ..

Directories

Path Synopsis
rpc

Jump to

Keyboard shortcuts

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