1 Star 0 Fork 0

shishshinedone/coauth

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
public.go 1.54 KB
Copy Edit Raw Blame History
Harold authored 2021-11-05 14:13 +08:00 . 修订接口
package coauth
import (
"time"
"gitee.com/shishshinedone/coauth/coauth_core"
)
type Option func(o *coauth_core.Options)
func WithTimeout(value time.Duration) Option {
return func(o *coauth_core.Options) {
o.Timeout = value
}
}
type version string
const (
VersionOriginal version = coauth_core.VersionOriginal
)
func WithVersion(value version) Option {
return func(o *coauth_core.Options) {
o.Version = string(value)
}
}
type mode int
const (
ModeClient mode = coauth_core.ModeClient
ModePassword mode = coauth_core.ModePassword
)
func WithMode(value mode) Option {
return func(o *coauth_core.Options) {
o.Mode = int(value)
}
}
// GrantTypePassword模式有效
func WithGrantUsername(value string) Option {
return func(o *coauth_core.Options) {
o.GrantUsername = value
}
}
// GrantTypePassword模式有效
func WithGrantPassword(value string) Option {
return func(o *coauth_core.Options) {
o.GrantPassword = value
}
}
type scope string
const (
ScopeRead scope = coauth_core.ScopeRead
ScopeReadWrite scope = coauth_core.ScopeReadWrite
)
func WithScope(value scope) Option {
return func(o *coauth_core.Options) {
o.Scope = string(value)
}
}
type Coauth coauth_core.Coauth
func NewCoauth(addr, username, password string, optionArray ...Option) Coauth {
options := &coauth_core.Options{
Version: coauth_core.VersionOriginal,
Mode: coauth_core.ModeClient,
Scope: coauth_core.ScopeReadWrite,
}
for _, option := range optionArray {
option(options)
}
return coauth_core.NewCoauth(addr, username, password, options)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/shishshinedone/coauth.git
git@gitee.com:shishshinedone/coauth.git
shishshinedone
coauth
coauth
v1.0.3

Search