auth

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2025 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlagSet

func FlagSet(name string) *pflag.FlagSet

func Init

func Init(c *Config) gin.HandlerFunc

Types

type AuthType

type AuthType string
const (
	AuthTypeApikey  AuthType = "apikey"
	AuthTypeToken   AuthType = "token"   // +redis
	AuthTypeSession AuthType = "session" // ?+redis
	AuthTypeCookie  AuthType = "cookie"  // ?+redis

)

type Config

type Config struct {
	Enabled bool     `json:"enabled" yaml:"enabled"`
	Type    AuthType `json:"type" yaml:"type"`
	MaxAge  int      `json:"maxage" yaml:"maxage"` // Expire(MaxAge)

	// Cookie
	Secret string `json:"secret" yaml:"secret"` // Cookie Secret

	// Token | Redis
	Host string `json:"host" yaml:"host"` // Redis Address
	Port int    `json:"port" yaml:"port"` // Redis Port
	Pass string `json:"pass" yaml:"pass"` // Redis Password
	DB   int    `json:"db" yaml:"db"`     // Redis DB
}

func (*Config) Addr

func (s *Config) Addr() string

func (*Config) WithAddr

func (s *Config) WithAddr(v string) *Config

func (*Config) WithDB

func (s *Config) WithDB(v int) *Config

func (*Config) WithMaxAge

func (s *Config) WithMaxAge(v int) *Config

func (*Config) WithPass

func (s *Config) WithPass(v string) *Config

func (*Config) WithPort

func (s *Config) WithPort(v int) *Config

type Session

type Session interface {
	Token() string

	ID() string
	Get(string) any
	Account() string
	Roles() []string
	HasRole(string) bool

	Delete(string)
	Clear()

	Set(string, any)
	SetAccount(string)
	SetID(string)
	SetRoles([]string)
	SetValues(string, any)
	Save(...time.Duration) error
}

func Default

func Default(c *gin.Context) Session

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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