server

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2022 License: Zlib Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	AT_DEF     = AuthType(0)
	AT_NAME    = AuthType(1)  //用户名
	AT_PHONE   = AuthType(2)  //手机
	AT_EMAIL   = AuthType(3)  //邮箱
	AT_WEIXIN  = AuthType(4)  //微信(第三方)
	AT_WEIBIO  = AuthType(5)  //微博(第三方)
	AT_QQ      = AuthType(6)  //QQ (第三方)
	AT_WXMINI  = AuthType(7)  //微信小程序(第三方)
	AT_WXSER   = AuthType(8)  //微信服务号(第三方)
	AT_TODAY   = AuthType(9)  //今日头条(第三方)
	AT_BAIDU   = AuthType(10) //百度(第三方)
	AT_TOKEN   = AuthType(99) //业务TOKEN验证
	AT_VISITOR = AuthType(100)
	AT_INNER   = AuthType(101)
	AT_END     = AuthType(102)
)
View Source
const (
	AS_DEF        = AuthStatus(0) //0=未激活 1=正在.. 2=已激活 3=删除
	AS_ACTIVATING = AuthStatus(1)
	AS_ACTIVATED  = AuthStatus(2)
	AS_DELETED    = AuthStatus(3)
)
View Source
const (
	AM_DEF  = AuthMethod(0)
	AM_PASS = AuthMethod(1) //密码
	AM_SMS  = AuthMethod(2) //短信
	AM_END  = AuthMethod(3)
)
View Source
const (
	VT_DEF        = ValidatingType(0)
	VT_REG_SMS    = ValidatingType(1) //注册短信
	VT_LOG_SMS    = ValidatingType(2) //登录短信
	VT_REG_INVITE = ValidatingType(3) //注册邀请
	VT_ACT_EMAIL  = ValidatingType(4)
	VT_END        = ValidatingType(255)
)
View Source
const (
	//PC MAC IPHONE IPAD APHONE APAD TV
	PT_PC     = "pc"
	PT_MAC    = "mac"
	PT_IPHONE = "iphone"
	PT_IPAD   = "ipad"
	PT_APHONE = "aphone"
	PT_APAD   = "apad"
	PT_TV     = "tv"
)
View Source
const (
	GHealthTtl = 10
)

Variables

This section is empty.

Functions

func GenerateClient

func GenerateClient(session Session, auth int8, app app.Info, expire int32, source string) (string, error)

func GenerateServer

func GenerateServer(session Session, auth int8, app app.Info, expire int32) (string, error)

func GenerateServerToken

func GenerateServerToken(source app.Source) string

func IsClientAuthenticate

func IsClientAuthenticate(source app.Source) bool

func IsServerAuthenticate

func IsServerAuthenticate(source app.Source) bool

func SetClientAuthenticate

func SetClientAuthenticate(auth Authenticate)

func SetServerAuthenticate

func SetServerAuthenticate(auth Authenticate)

func UserTokenToServerToken

func UserTokenToServerToken(userToken, source string) (string, error)

UserTokenToServerToken 从用户端到服务器,服务器到服务器之间需要的认证

Types

type Address added in v0.1.2

type Address struct {
	Scheme  string `json:"scheme"`
	Host    string `json:"host"`
	Port    int    `json:"port"`
	Weight  int    `json:"weight"`
	Timeout int    `json:"timeout"`
	Path    string `json:"path"`
	Name    string `json:"name"`
}

func Parse

func Parse(addr string) (Address, error)

func ParseWithSeparate added in v0.1.2

func ParseWithSeparate(info string) Address

name|scheme://host:post|timeout|weight

func (Address) HasDomain added in v0.1.2

func (s Address) HasDomain() bool

简单的域名 .com,.cn

func (Address) HasIP added in v0.1.2

func (s Address) HasIP() bool

func (Address) HasPort added in v0.1.2

func (s Address) HasPort() bool

func (Address) IsHttp added in v0.1.2

func (s Address) IsHttp() bool

func (Address) IsScheme added in v0.1.2

func (s Address) IsScheme(scheme string) bool

func (Address) SetHost added in v0.1.2

func (s Address) SetHost(host string)

func (Address) To added in v0.1.2

func (s Address) To() string

To scheme://host:port

type Array added in v0.1.2

type Array []Address

func NewArray added in v0.1.2

func NewArray() Array

func (Array) Add added in v0.1.2

func (ay Array) Add(addr string)

@param addr = host:port

func (Array) Array added in v0.1.2

func (ay Array) Array() []string

func (Array) ToWeight added in v0.1.2

func (ay Array) ToWeight() Array

type AuthMethod

type AuthMethod int8

认证方法

func (AuthMethod) Int

func (a AuthMethod) Int() int8

type AuthStatus

type AuthStatus int8

认证状态

func (AuthStatus) Int

func (a AuthStatus) Int() int8

type AuthType

type AuthType int8

认证 1=用户名, 2=手机 3=邮箱 4=微信 5=微博 6=QQ 7=小程序

func (AuthType) Int

func (a AuthType) Int() int8

type Authenticate

type Authenticate interface {
	Generate(session Session, auth int8, app app.Info, expire int32) (string, error)
	IsEnabled(source app.Source) bool
	SetEnabled(source app.Source, enable bool)
	Check(source app.Source, token string) (*Token, error)
}

type AuthenticateFunc

type AuthenticateFunc func(source app.Source, token string) (*Token, error)

type ByWeight added in v0.1.2

type ByWeight []Address

func (ByWeight) Len added in v0.1.2

func (a ByWeight) Len() int

func (ByWeight) Less added in v0.1.2

func (a ByWeight) Less(i, j int) bool

func (ByWeight) Swap added in v0.1.2

func (a ByWeight) Swap(i, j int)

type Cluster

type Cluster struct {
	Nodes        []Address     `json:"nodes"`
	Password     string        `json:"password"`
	PoolSize     int           `json:"pool_size"`
	ReadOnly     bool          `json:"read_only"`
	DialTimeout  time.Duration `json:"dial_timeout"`
	ReadTimeout  time.Duration `json:"read_timeout"`
	WriteTimeout time.Duration `json:"write_timeout"`
}

Cluster 集群配置

type Current added in v0.1.2

type Current struct {
	Adders Array
	// contains filtered or unexported fields
}

func NewCurrent added in v0.1.2

func NewCurrent() Current

func (Current) Add added in v0.1.2

func (a Current) Add(addr Address)

func (Current) Current added in v0.1.2

func (a Current) Current() Address

func (Current) Next added in v0.1.2

func (a Current) Next() Address

type Database

type Database struct {
	Host       string `json:"host"`
	Port       int    `json:"port"`
	User       string `json:"user"`
	Pwd        string `json:"pwd"`
	DriverType string `json:"type"` //mysql, sqlite
	Name       string `json:"name"` //数据库名
}

func (Database) GetDataSourceName

func (d Database) GetDataSourceName() string

type Domain added in v0.1.2

type Domain struct {
	Domain string `json:"-"`
	Raw    string `json:"domain"`
}

func (Domain) DomainTo added in v0.1.2

func (c Domain) DomainTo() string

type Elastic

type Elastic struct {
	Address
	XPackSecurityUser string `json:"xpack_security_user"`
	Name              string `json:"name"`
	User              string `json:"user"`
	Pwd               string `json:"pwd"`
	Sniff             bool   `json:"sniff"`
}

type EndPoints

type EndPoints struct {
	Servers Array  `json:"servers"`
	Type    string `json:"type"` //IP直连,不需要向consul,etcd,dubbo注册
}

func ReadEndPoints

func ReadEndPoints() (EndPoints, error)

func ReadEndPointsFromFile

func ReadEndPointsFromFile(filename string) (EndPoints, error)

type HealthCheck

type HealthCheck struct {
	Ttl      bool          `json:"ttl"`
	GRpc     bool          `json:"grpc"`
	Http     bool          `json:"http"`
	Tcp      bool          `json:"tcp"`
	Interval time.Duration `json:"interval"` //(second)
	Value    string        `json:"value"`
}

func ReadHealthCheck

func ReadHealthCheck() (HealthCheck, error)

func (*HealthCheck) IsGRpc

func (hc *HealthCheck) IsGRpc() bool

func (*HealthCheck) IsHttp

func (hc *HealthCheck) IsHttp() bool

func (*HealthCheck) IsTcp

func (hc *HealthCheck) IsTcp() bool

func (*HealthCheck) IsTtl

func (hc *HealthCheck) IsTtl() bool

type Local

type Local struct {
	Name    string
	Version string
	AppId   string
}

type MqClient

type MqClient struct {
	GroupID      string `json:"groupId"`
	Server       string `json:"server"`
	Domain       string `json:"domain"`
	GroupName    string `json:"groupName"`
	InstanceName string `json:"instance"`
}

type MqConfig

type MqConfig struct {
	Client       MqClient         `json:"client"`
	Credentials  MqCredentials    `json:"credentials"`
	LogLevel     int              `json:"logLevel"`
	ProducerConf MqProducerConfig `json:"producer"`
	ConsumerConf MqConsumerConfig `json:"consumer"`
}

type MqConsumerConfig

type MqConsumerConfig struct {
	ThreadCount int `json:"threadcount"`
	Model       int `json:"model"`
	Size        int `json:"batchmaxsize"`
}

type MqCredentials

type MqCredentials struct {
	AccessKey   string `json:"accessKey"`
	SecretKey   string `json:"secretKey"`
	SecretToken string `json:"secretToken"`
}

type MqProducerConfig

type MqProducerConfig struct {
	Timeout  int `json:"timeout"`
	Compress int `json:"compresslevel"`
	Size     int `json:"maxmessagesize"`
	Retry    int `json:"retry"`
}

type Node

type Node struct {
	Root      string
	Service   string
	RpcMethod string
}

func NodeWith

func NodeWith(source, build string) Node

func (Node) NameWith

func (s Node) NameWith(build string) string

func (Node) NameWithRoot

func (s Node) NameWithRoot(build string) string

func (Node) SetType

func (s Node) SetType(t string)

type Redis

type Redis struct {
	Name string `json:"name"` //redis名
	Host string `json:"host"`
	Port int    `json:"port"`
	User string `json:"user"`
	Pwd  string `json:"pwd"`
	DB   int    `json:"db"`
}

type Secret

type Secret struct {
	Secret string `json:"secret"`
	Expire int32  `json:"expireIn"`
}

func (*Secret) ExpireIn

func (s *Secret) ExpireIn() int32

func (*Secret) Key

func (s *Secret) Key() []byte

type Session added in v0.2.0

type Session struct {
	Uid     string `json:"uid"`
	Session string `json:"-"`
}

type Sql

type Sql struct {
	Master       Database      `json:"master"`
	Sources      []Database    `json:"sources"`
	Replicas     []Database    `json:"replicas"`
	MaxOpenConns int           `json:"max_open_conns"`
	MaxIdleConns int           `json:"max_idle_conns"`
	MaxIdleTime  time.Duration `json:"max_idle_time"`
}

type Token

type Token struct {
	Session
	Token string `json:"token"`
	// contains filtered or unexported fields
}

func AuthenticateWithClient

func AuthenticateWithClient(source app.Source, token string) (*Token, error)

func AuthenticateWithServer

func AuthenticateWithServer(source app.Source, token string) (*Token, error)

func New

func New(key TokenKey) *Token

func UnVerifyToken

func UnVerifyToken(tk string) (*Token, error)

UnVerifyToken *

  • 不需要认证,解包里面的信息

func VerifyToken

func VerifyToken(tk string, key TokenKey) (*Token, error)

VerifyToken *

  • 需要认证,解包里面的信息

func (*Token) Generate

func (tk *Token) Generate(session Session, auth int8, app app.Info) (string, error)

func (*Token) GetApp

func (tk *Token) GetApp() app.Info

func (*Token) GetAuthType

func (tk *Token) GetAuthType() int8

func (*Token) GetKey

func (tk *Token) GetKey() TokenKey

func (*Token) Update

func (tk *Token) Update() (string, error)

type TokenKey

type TokenKey interface {
	Key() []byte
	ExpireIn() int32
}

type ValidatingType

type ValidatingType int

验证类型

func (ValidatingType) Int

func (a ValidatingType) Int() int

Jump to

Keyboard shortcuts

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