feat: initial commit
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
This commit is contained in:
9
internal/queue/options.go
Normal file
9
internal/queue/options.go
Normal file
@ -0,0 +1,9 @@
|
||||
package queue
|
||||
|
||||
type Options struct{}
|
||||
|
||||
type OptionFunc func(*Options)
|
||||
|
||||
func defaultOptions() *Options {
|
||||
return &Options{}
|
||||
}
|
32
internal/queue/queue.go
Normal file
32
internal/queue/queue.go
Normal file
@ -0,0 +1,32 @@
|
||||
package queue
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"forge.cadoles.com/Cadoles/go-proxy"
|
||||
)
|
||||
|
||||
type Queue struct {
|
||||
repository Repository
|
||||
}
|
||||
|
||||
func (q *Queue) Middleware() proxy.Middleware {
|
||||
return func(next http.Handler) http.Handler {
|
||||
fn := func(w http.ResponseWriter, r *http.Request) {
|
||||
next.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
return http.HandlerFunc(fn)
|
||||
}
|
||||
}
|
||||
|
||||
func New(repository Repository, funcs ...OptionFunc) *Queue {
|
||||
opts := defaultOptions()
|
||||
for _, fn := range funcs {
|
||||
fn(opts)
|
||||
}
|
||||
|
||||
return &Queue{
|
||||
repository: repository,
|
||||
}
|
||||
}
|
65
internal/queue/redis/repository.go
Normal file
65
internal/queue/redis/repository.go
Normal file
@ -0,0 +1,65 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"forge.cadoles.com/cadoles/bouncer/internal/queue"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
type Repository struct {
|
||||
client redis.UniversalClient
|
||||
}
|
||||
|
||||
// GetQueue implements queue.Repository
|
||||
func (*Repository) GetQueue(ctx context.Context, name string) (int, int, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// CreateQueue implements queue.Repository
|
||||
func (*Repository) CreateQueue(ctx context.Context, name string, capacity int) error {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// CreateToken implements queue.Repository
|
||||
func (*Repository) CreateToken(ctx context.Context, name string) (string, int, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// DeleteQueue implements queue.Repository
|
||||
func (*Repository) DeleteQueue(ctx context.Context, name string) error {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// GetTokenPosition implements queue.Repository
|
||||
func (*Repository) GetTokenPosition(ctx context.Context, name string, token string) (int, int, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// RefreshQueue implements queue.Repository
|
||||
func (*Repository) RefreshQueue(ctx context.Context, name string) (int, int, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// RemoveToken implements queue.Repository
|
||||
func (*Repository) RemoveToken(ctx context.Context, name string, token string) error {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// TouchToken implements queue.Repository
|
||||
func (*Repository) TouchToken(ctx context.Context, name string, token string) (int, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// UpdateQueue implements queue.Repository
|
||||
func (*Repository) UpdateQueue(ctx context.Context, name string, capacity int) error {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
func NewRepository(client redis.UniversalClient) *Repository {
|
||||
return &Repository{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
|
||||
var _ queue.Repository = &Repository{}
|
16
internal/queue/repository.go
Normal file
16
internal/queue/repository.go
Normal file
@ -0,0 +1,16 @@
|
||||
package queue
|
||||
|
||||
import "context"
|
||||
|
||||
type Repository interface {
|
||||
CreateQueue(ctx context.Context, name string, capacity int) error
|
||||
GetQueue(ctx context.Context, name string) (int, int, error)
|
||||
UpdateQueue(ctx context.Context, name string, capacity int) error
|
||||
DeleteQueue(ctx context.Context, name string) error
|
||||
RefreshQueue(ctx context.Context, name string) (int, int, error)
|
||||
|
||||
CreateToken(ctx context.Context, name string) (string, int, error)
|
||||
GetTokenPosition(ctx context.Context, name string, token string) (int, int, error)
|
||||
TouchToken(ctx context.Context, name string, token string) (int, error)
|
||||
RemoveToken(ctx context.Context, name string, token string) error
|
||||
}
|
Reference in New Issue
Block a user