common

package module
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2019 License: MIT Imports: 22 Imported by: 0

README

common

公用方法

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIer added in v0.0.7

type APIer interface {
	// API 应用接口
	API() Partyer
}

APIer 路由器

type App added in v0.0.3

type App struct {
	DB    *gorm.DB
	CS    *Service
	AS    *AuthService
	APIer APIer

	Log *golog.Logger
}

App 应用

func NewApp added in v0.0.3

func NewApp(db *gorm.DB, cs *Service, as *AuthService, apier APIer) *App

NewApp 新建应用

func (*App) Run added in v0.0.3

func (a *App) Run(c *Config)

Run 运行

type AuthService added in v0.0.7

type AuthService struct {
	DB      *gorm.DB
	CS      *Service
	US      *UserService
	TS      *wx.TokenService
	Creater Creater
	WxURL   string
}

AuthService 身份认证

func NewAuthService added in v0.0.7

func NewAuthService(db *gorm.DB, cs *Service, us *UserService, ts *wx.TokenService, creater Creater) *AuthService

NewAuthService 新建身份认证服务

func (*AuthService) Party added in v0.0.7

func (s *AuthService) Party(p iris.Party)

Party 身份认证分组

type Code added in v0.0.7

type Code struct {
	IDModel
	Jwt string `gorm:"size:200" json:"jwt"` // 用户jwt
}

Code 用户登录身份识别

type Command

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

Command 命令行

func NewCommand

func NewCommand(cmd *cobra.Command) *Command

NewCommand 新疆命令行参数

func (*Command) Bool

func (c *Command) Bool(name string) bool

Bool 读取配置String

func (*Command) Int

func (c *Command) Int(name string) int

Int 读取配置Int

func (*Command) String

func (c *Command) String(name string) string

String 读取配置String

type Config added in v0.0.3

type Config struct {
	Name      string // 应用名称
	Address   string // 监听端口
	Secret    []byte // JWT密钥
	MockID    string // 模拟用户ID
	Develop   bool   // 开发模式
	Redirect  string // 重定向目录
	LogDir    string // 日志目录
	StaticDir string // 静态资源目录
	WxURL     string // 微信首页
}

Config 配置信息

type Creater added in v0.0.8

type Creater interface {
	Create(user *User)
}

Creater 创建

type FieldError

type FieldError struct {
	Field string `json:"field"` // 字段
	Tag   string `json:"tag"`   // 标签
	Param string `json:"param"` // 参数
}

FieldError 字段错误信息

type IDModel added in v0.0.4

type IDModel struct {
	ID        string    `gorm:"primary_key;size:22" json:"id"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

IDModel 主键UUID模型

func (*IDModel) BeforeCreate added in v0.0.4

func (m *IDModel) BeforeCreate(scope *gorm.Scope) error

BeforeCreate 创建实体前生成UUID

type Issue added in v0.0.10

type Issue struct {
	NumModel
	UserID      string  `gorm:"primary_key;size:22" json:"userID"`                  // 用户主键
	Title       string  `gorm:"size:100;not null" json:"title" validate:"required"` // 标题
	Description string  `gorm:"size:250" json:"description"`                        // 说明
	Replies     []Reply `gorm:"foreignkey:IssueID" json:"-"`                        // 回复
	Echo        string  `gorm:"size:250" json:"echo"`                               // 回音
}

Issue 问题

type IssueService added in v0.0.10

type IssueService struct {
	DB *gorm.DB
	CS *Service
	US *UserService
}

IssueService 问题服务

func NewIssueService added in v0.0.10

func NewIssueService(db *gorm.DB, cs *Service, us *UserService) *IssueService

NewIssueService 新建问题服务

func (*IssueService) Party added in v0.0.10

func (s *IssueService) Party(p iris.Party)

Party 分组

type LoginForm added in v0.0.7

type LoginForm struct {
	Phone    string `validate:"required"` // 手机
	Password string `validate:"required"` // 密码
}

LoginForm 用户登录

type NumModel added in v0.0.4

type NumModel struct {
	ID        int       `gorm:"primary_key;auto_increment:false" json:"id"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

NumModel 主键int模型

type Partyer added in v0.0.3

type Partyer interface {
	Party(p iris.Party)
}

Partyer 服务注册

type Reply added in v0.0.10

type Reply struct {
	IDModel
	IssueID int    `json:"issueID"`                 // 问题主键
	UserID  string `gorm:"size:22" json:"userID"`   // 用户主键
	Content string `gorm:"size:250" json:"content"` // 内容
	Echo    string `gorm:"size:250" json:"echo"`    // 回音
}

Reply 问题

type ReplyService added in v0.0.10

type ReplyService struct {
	DB *gorm.DB
	CS *Service
	IS *IssueService
}

ReplyService 回复服务

func NewReplyService added in v0.0.10

func NewReplyService(db *gorm.DB, cs *Service, is *IssueService) *ReplyService

NewReplyService 新建问题服务

func (*ReplyService) Party added in v0.0.10

func (s *ReplyService) Party(p iris.Party)

Party 分组

type Service

type Service struct {
	Logger *golog.Logger
	// contains filtered or unexported fields
}

Service 公共服务

func NewService

func NewService() *Service

NewService 新建公共服务

func (*Service) Bind

func (s *Service) Bind(ctx iris.Context, obj interface{}, errMsg string) bool

Bind 对象绑定

func (*Service) Filter added in v0.0.11

func (s *Service) Filter(db *gorm.DB, ctx iris.Context) *gorm.DB

Filter 数据库过滤

func (*Service) Get

func (s *Service) Get(url string, p interface{}) error

Get 请求

func (*Service) Int

func (s *Service) Int(ctx iris.Context, name, errMsg string) int

Int 路径中的整数

func (*Service) String

func (s *Service) String(ctx iris.Context, name, errMsg string) string

String 路径中的字符串

func (*Service) URLInt

func (s *Service) URLInt(ctx iris.Context, name, errMsg string) int

URLInt query中的整数

func (*Service) URLString

func (s *Service) URLString(ctx iris.Context, name, errMsg string) string

URLString query中的字符串

type User added in v0.0.5

type User struct {
	IDModel
	IssuesNum  int    `gorm:"default:0" json:"-"`            // 问题数量
	Nick       string `gorm:"size:60" json:"nickname"`       // 昵称
	Openid     string `gorm:"size:36" json:"openid"`         // 微信ID
	Unionid    string `gorm:"unique;size:36" json:"unionid"` // 微信唯一标识
	Sex        int    `json:"sex"`                           // 性别
	Province   string `gorm:"size:36" json:"province"`       // 省份
	City       string `gorm:"size:36" json:"city"`           // 城市
	Country    string `gorm:"size:16" json:"country"`        // 国家
	Headimgurl string `gorm:"size:250" json:"headimgurl"`    // 头像
	// 用户可修改
	Phone    string `gorm:"size:20" json:"phone"` // 手机
	Password string `gorm:"-" json:"token"`       // 密码
	Cipher   []byte `gorm:"size:16" json:"-"`     // 密文
}

User 用户

func (*User) BeforeCreate added in v0.0.5

func (u *User) BeforeCreate(scope *gorm.Scope) error

BeforeCreate 创建用户前加密密码

func (*User) Check added in v0.0.5

func (u *User) Check() bool

Check 密码检查

func (*User) Encode added in v0.0.5

func (u *User) Encode(id string) []byte

Encode 加密

type UserService added in v0.0.5

type UserService struct {
	DB     *gorm.DB
	Secret []byte
}

UserService 用户服务

func NewUserService added in v0.0.5

func NewUserService(db *gorm.DB, secret []byte) *UserService

NewUserService 新建用户服务

func (*UserService) Find added in v0.0.6

func (s *UserService) Find(unionid string, user interface{})

Find 查找用户,参数是用户指针

func (*UserService) GetUser added in v0.0.5

func (s *UserService) GetUser(ctx iris.Context, user interface{})

GetUser 获取用户

func (*UserService) GetUserID added in v0.0.5

func (s *UserService) GetUserID(ctx iris.Context) string

GetUserID 获取用户ID

func (*UserService) Party added in v0.0.5

func (s *UserService) Party(p iris.Party)

Party 分组

func (*UserService) Token added in v0.0.5

func (s *UserService) Token(userID string) string

Token 生成token

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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