rest

package
v0.0.0-...-93a69da Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("resource not found")

Functions

func Bind

func Bind(r bunrouter.Request, ans any) error

func JSON

func JSON(w http.ResponseWriter, statusCode int, value interface{}) error

func New

func New(cfg ServerConfig) (*server, error)

func NewRouter

func NewRouter(cfg RouterConfig) *bunrouter.Router

Types

type AuthService

type AuthService interface {
	Signup(ctx context.Context, username string) (string, error)
	AuthMiddleware(next bunrouter.HandlerFunc) bunrouter.HandlerFunc
	InternalApi(next bunrouter.HandlerFunc) bunrouter.HandlerFunc
}

type ExecutionResponse

type ExecutionResponse struct {
	StatusCode int       `json:"statusCode"`
	Msg        string    `json:"msg"`
	ExecutedAt time.Time `json:"executedAt"`
}

type HTTPError

type HTTPError struct {
	StatusCode int `json:"-"`

	Message string `json:"message"`
}

func NewHTTPError

func NewHTTPError(err error) HTTPError

func (HTTPError) Error

func (e HTTPError) Error() string

type HealthHandler

type HealthHandler struct {
	// contains filtered or unexported fields
}

func (*HealthHandler) Get

type HealthResponse

type HealthResponse struct {
	ServerUpSince  time.Time `json:"serverUpSince"`
	WorkersHealthy bool      `json:"workersHealthy"`
	DbHealthy      bool      `json:"dbHealthy"`
}

type MetaHandler

type MetaHandler struct {
	// contains filtered or unexported fields
}

func (*MetaHandler) Get

type MetaResponse

type MetaResponse struct {
	PublicKey string `json:"publicKey"`
}

type NotFoundError

type NotFoundError struct {
	Message string
}

func (NotFoundError) Error

func (e NotFoundError) Error() string

type RegisterPayload

type RegisterPayload struct {
	Name string `json:"name"`
}

type RegisterResponse

type RegisterResponse struct {
	Partition int `json:"partition"`
}

type ResponseWriter

type ResponseWriter struct {
	Wrapped http.ResponseWriter
	// contains filtered or unexported fields
}

func NewResponseWriter

func NewResponseWriter(w http.ResponseWriter) *ResponseWriter

func (*ResponseWriter) StatusCode

func (w *ResponseWriter) StatusCode() int

type RouterConfig

type RouterConfig struct {
	Log             zerolog.Logger
	ScheduledJobSrv ScheduledJobService
	WorkerSrv       WorkerService
	AuthSrv         AuthService
	PublicKey       *ecdsa.PublicKey
}

type ScheduledJobGetResponse

type ScheduledJobGetResponse struct {
	UID         uuid.UUID           `json:"uid"`
	Name        string              `json:"name"`
	Description string              `json:"description"`
	Url         string              `json:"url"`
	RunAt       time.Time           `json:"runAt"`
	Status      string              `json:"status"`
	Executions  []ExecutionResponse `json:"executions"`
}

type ScheduledJobResponse

type ScheduledJobResponse struct {
	UUID string `json:"uuid"`
}

type ScheduledJobService

type ScheduledJobService interface {
	Get(ctx context.Context, u entities.User, uid string) (entities.ScheduledJob, []entities.Execution, error)
	Schedule(ctx context.Context, job entities.ScheduledJob) (entities.ScheduledJob, error)
}

type ScheduledJobsHandler

type ScheduledJobsHandler struct {
	// contains filtered or unexported fields
}

func (*ScheduledJobsHandler) Create

func (*ScheduledJobsHandler) Get

type ScheduledJobsPayload

type ScheduledJobsPayload struct {
	Name        string    `json:"name"`
	Description string    `json:"description"`
	Url         string    `json:"url"`
	Payload     string    `json:"payload"`
	ContentType string    `json:"contentType"`
	Signature   string    `json:"signature"`
	RunAt       time.Time `json:"runAt"`
	Retries     int       `json:"retries"`
}

TODO validate

func (ScheduledJobsPayload) Validate

func (s ScheduledJobsPayload) Validate() error

type ServerConfig

type ServerConfig struct {
	Log          zerolog.Logger
	Addr         string
	WriteTimeout time.Duration
	ReadTimeout  time.Duration
	IdleTimeout  time.Duration
	Handler      http.Handler
	Domain       string
}

type SignupPayload

type SignupPayload struct {
	Username string
}

func (SignupPayload) Validate

func (o SignupPayload) Validate() error

type SignupResponse

type SignupResponse struct {
	Apikey string `json:"apiKey"`
}

type UserHandler

type UserHandler struct {
	// contains filtered or unexported fields
}

func (*UserHandler) Create

type ValidationError

type ValidationError struct {
	Message string
}

func (ValidationError) Error

func (e ValidationError) Error() string

type WorkerHandler

type WorkerHandler struct {
	// contains filtered or unexported fields
}

func (*WorkerHandler) HealthHandler

func (h *WorkerHandler) HealthHandler(w http.ResponseWriter, r bunrouter.Request) error

func (*WorkerHandler) Register

func (*WorkerHandler) UnRegister

type WorkerService

type WorkerService interface {
	Register(ctx context.Context, name string) (entities.WorkerMeta, error)
	UnRegister(ctx context.Context, name string) (entities.WorkerMeta, error)
	Health(ctx context.Context, name string) error
	UpSince(ctx context.Context) time.Time
	ActiveWorkers(ctx context.Context) int
	DbOk(ctx context.Context) bool
}

Jump to

Keyboard shortcuts

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