Help us shape the future of Go! Take the 2026 Go Developer Survey

api

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	API_KEY_DEFAULT_HEADER   = "X-API-KEY"
	SIGNATURE_DEFAULT_HEADER = "X-Signature"
	TIMESTAMP_DEFAULT_HEADER = "X-Timestamp"
)
View Source
const MAX_EXTRA_SIZE = 2048

Variables

View Source
var ErrInvalidApiKey = errors.New("Invalid API key")
View Source
var ErrUnauthorized = errors.New("Unauthorized")

Functions

This section is empty.

Types

type Api

type Api struct {
	Log    *slog.Logger
	Db     *sql.DB
	Config Config
	// contains filtered or unexported fields
}

func NewApi added in v0.1.11

func NewApi(log *slog.Logger, db *sql.DB, config Config) (*Api, error)

func (*Api) Check

func (a *Api) Check(c *gin.Context)

func (*Api) CheckOrVerify added in v0.1.12

func (a *Api) CheckOrVerify(c *gin.Context)

func (*Api) CreateApiKey

func (a *Api) CreateApiKey(c *gin.Context)

func (*Api) GetApiKey

func (a *Api) GetApiKey(c *gin.Context)

func (*Api) HealthLiveness added in v0.1.1

func (a *Api) HealthLiveness(c *gin.Context)

func (*Api) HealthMetrics added in v0.1.1

func (a *Api) HealthMetrics(c *gin.Context)

func (*Api) HealthReadiness added in v0.1.1

func (a *Api) HealthReadiness(c *gin.Context)

func (*Api) ListApiKeys

func (a *Api) ListApiKeys(c *gin.Context)

func (*Api) Routes

func (a *Api) Routes(prefix string) *gin.Engine

func (*Api) Verify added in v0.1.1

func (a *Api) Verify(c *gin.Context)

type ApiKey

type ApiKey struct {
	Id     int64
	Secret []byte
}

func ParseApiKey

func ParseApiKey(apiKey string) (*ApiKey, error)

func (*ApiKey) String

func (a *ApiKey) String() string

type ApiKeyResponse

type ApiKeyResponse struct {
	Id    int64           `json:"id"`
	Sub   string          `json:"sub"`
	Name  string          `json:"name"`
	Alg   string          `json:"alg"`
	Key   string          `json:"key"`
	Exp   time.Time       `json:"exp"`
	Extra json.RawMessage `json:"extra,omitempty"`
}

type Config

type Config struct {
	ApiKeyHeaderName     string
	ApiKeyQueryParamName string
	SignatureHeaderName  string
	SignatureQueryParam  string
	TimestampHeaderName  string
	TimestampQueryParam  string
	TimestampExpiration  time.Duration
	DefaultKeyExpiration time.Duration
	CacheMaxSize         uint64
	CacheTTL             time.Duration
}

Jump to

Keyboard shortcuts

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