draken

package module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: BSD-3-Clause Imports: 34 Imported by: 0

README


Logo

Draken

A Go framework utilizing Echo for building backend services

Report Bug . Request Feature

License Contributors Issues

Table Of Contents

About The Project

Screen Shot

Creating secure, efficient, and scalable authentication and authorization solutions from scratch can be a daunting and time-consuming task for developers. Recognizing this challenge, we've developed an authentication project designed to significantly simplify the integration of authentication and authorization mechanisms into your applications. This project is born out of the realization that developers spend an excessive amount of time reinventing the wheel for authentication flows, which detracts from focusing on the unique aspects of their own projects.

Here's why this authentication project is a game-changer for your development workflow:

  • Focus on Building Unique Features: Spend more time developing the core features that make your project stand out. Leave the complex and critical task of implementing secure authentication to us.
  • Avoid Repetitive Work: Stop writing authentication codes from scratch for every new project. Our solution provides a robust, flexible foundation that can be easily integrated and customized for a wide range of applications.
  • Embrace DRY Principles: Just like adhering to DRY (Don't Repeat Yourself) principles in your coding practices, applying the same philosophy to your project's authentication process can save time, reduce errors, and improve maintainability.

While we strive to make our authentication project as versatile as possible, we understand that no single solution can cater to every possible requirement. Therefore, we're committed to continuously evolving our project based on community feedback. You're encouraged to contribute by forking our repository, submitting pull requests, or opening issues to suggest improvements or new features.

In the near future, we plan to expand our project's capabilities to cover more authentication and authorization scenarios, ensuring it remains the most comprehensive and developer-friendly solution available.

Built With

We are using Go, Templ, Tailwind and Flowbite for the web application, MySQL for the Database and Redis as a Cache.

Getting Started

This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.

Prerequisites

This is an example of how to list things you need to use the software and how to install them.

  • make
  • go
  • npm
  • templ
  • air
Installation instructions will follow

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

We appreciate everyone who wants to contribute. In order to do so take a look at the issues tab and work on one of the issues. You can then create a pull request:

Creating A Pull Request

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the BSD-3 License. See LICENSE for more information.

Acknowledgements

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloudflareCompatibleIP added in v0.4.5

func CloudflareCompatibleIP(ctx echo.Context) string

func DrakenHandler

func DrakenHandler(w http.ResponseWriter, r *http.Request) (*Response, *Request)

func HeartbeatRoute added in v0.3.0

func HeartbeatRoute(ctx echo.Context) error

func LoggerMiddleware

func LoggerMiddleware(l zerolog.Logger) echo.MiddlewareFunc

func RequestIdMiddleware

func RequestIdMiddleware() echo.MiddlewareFunc

func WebserverMiddleware

func WebserverMiddleware() echo.MiddlewareFunc

Types

type Cache added in v0.4.0

type Cache interface {
	Init(bool)
	Stop()
	Get(key string) (*string, error)
	Set(key string, value any, ttl time.Duration) error
	Exists(key string) bool
	Expire(key string, ttl time.Duration) error
	Push(key string, value any) error
	Pop(key string) (string, error)
	Len(key string) (int64, error)
}

type CacheConfig added in v0.4.0

type CacheConfig struct {
	Enabled bool
	Type    CacheType
	DSN     string
}

type CacheType added in v0.4.0

type CacheType uint8
const (
	CacheTypeRedis CacheType = iota
)

type Config

type Config struct {
	Environment Environment
	Debug       bool
	Server      ServerConfig
	Storage     StorageConfig
	Cache       CacheConfig
	R2          R2Config
}

type ContextKey

type ContextKey string
const ContextKeyRequestId ContextKey = "draken-request-id"

type Draken

type Draken struct {
	Config    Config
	Storage   Storage
	Cache     Cache
	StartedAt time.Time
	R2        *R2
	Router    *Router
}

func New

func New() (*Draken, error)

func (*Draken) CreateRouter

func (d *Draken) CreateRouter()

func (*Draken) OverwriteLogger added in v0.5.2

func (d *Draken) OverwriteLogger(logger zerolog.Logger)

func (*Draken) Serve

func (d *Draken) Serve() error

func (*Draken) ServeTLS

func (d *Draken) ServeTLS(tlsConfig TLSConfig) error

type Environment

type Environment uint8
const (
	EnvironmentLocal Environment = iota
	EnvironmentDev
	EnvironmentStaging
	EnvironmentProd
)

type HeartbeatConfig

type HeartbeatConfig struct {
	Enabled  bool
	Endpoint string
}

type R2 added in v0.3.3

type R2 struct {
	AccountId       string
	AccessKeyId     string
	AccessKeySecret string
	Limiter         *rate.Limiter
	Client          *s3.Client
	Context         context.Context
	Cancel          context.CancelFunc
}

func NewR2 added in v0.3.3

func NewR2(accountId, accessKeyId, accessKeySecret string) *R2

type R2Config added in v0.3.3

type R2Config struct {
	Enabled         bool
	AccountId       string
	AccessKeyId     string
	AccessKeySecret string
}

type Redis added in v0.4.0

type Redis struct {
	Client  *redis.Client
	Context context.Context
	Cancel  context.CancelFunc
}

func NewRedis added in v0.4.0

func NewRedis(dsn string) *Redis

NewRedis creates a new Redis object

func (*Redis) Exists added in v0.4.0

func (r *Redis) Exists(key string) bool

func (*Redis) Expire added in v0.4.0

func (r *Redis) Expire(key string, ttl time.Duration) error

func (*Redis) Get added in v0.4.0

func (r *Redis) Get(key string) (*string, error)

func (*Redis) Init added in v0.4.0

func (r *Redis) Init(e bool)

func (*Redis) Len added in v0.4.8

func (r *Redis) Len(key string) (int64, error)

Len returns the length of the list stored at key.

func (*Redis) Pop added in v0.4.1

func (r *Redis) Pop(key string) (string, error)

Pop removes and returns the head element of the list at key. If the list is empty, it returns ("", nil), but you could also choose to return ("", redis.Nil) and let the caller distinguish that yourself.

func (*Redis) Push added in v0.4.1

func (r *Redis) Push(key string, value any) error

Push pushes a single value onto the tail of the list at key.

func (*Redis) Set added in v0.4.0

func (r *Redis) Set(key string, value any, ttl time.Duration) error

func (*Redis) Stop added in v0.4.0

func (r *Redis) Stop()

type Request

type Request struct {
	*http.Request
}

func GetRequest

func GetRequest(r *http.Request) *Request

func (*Request) CtxGetString

func (r *Request) CtxGetString(key ContextKey) string

func (*Request) RequestId

func (r *Request) RequestId() string

type Response

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

func GetResponse

func GetResponse(w http.ResponseWriter) *Response

func (*Response) Json

func (r *Response) Json(data any) *Response

func (*Response) SetContentType

func (r *Response) SetContentType(t string) *Response

func (*Response) SetHeader

func (r *Response) SetHeader(header string, value string) *Response

func (*Response) Status

func (r *Response) Status(code int) *Response

func (*Response) Text

func (r *Response) Text(text string) (int, error)

type Router added in v0.2.0

type Router struct {
	Echo         *echo.Echo
	Group        *echo.Group
	Draken       *Draken
	ParentRouter *Router
	Subrouters   map[string]*Router
}

func (*Router) CreateSubrouter added in v0.2.0

func (r *Router) CreateSubrouter(route string) *Router

func (*Router) Delete added in v0.2.0

func (r *Router) Delete(route string, handler echo.HandlerFunc, middlewares ...echo.MiddlewareFunc)

func (*Router) EssentialMiddlewares added in v0.2.0

func (r *Router) EssentialMiddlewares()

func (*Router) Get added in v0.2.0

func (r *Router) Get(route string, handler echo.HandlerFunc, middlewares ...echo.MiddlewareFunc)

func (*Router) Middleware added in v0.2.0

func (r *Router) Middleware(middlewares ...echo.MiddlewareFunc)

func (*Router) Patch added in v0.2.0

func (r *Router) Patch(route string, handler echo.HandlerFunc, middlewares ...echo.MiddlewareFunc)

func (*Router) Post added in v0.2.0

func (r *Router) Post(route string, handler echo.HandlerFunc, middlewares ...echo.MiddlewareFunc)

func (*Router) Put added in v0.2.0

func (r *Router) Put(route string, handler echo.HandlerFunc, middlewares ...echo.MiddlewareFunc)

type ServerConfig

type ServerConfig struct {
	Hidden    bool
	Port      uint16
	Heartbeat HeartbeatConfig
	Security  bool
}

type SqlDatabase

type SqlDatabase struct {
	DB      *sql.DB
	Client  *bun.DB
	Context context.Context
	Cancel  context.CancelFunc
}

func NewLibsql

func NewLibsql(dsn string) *SqlDatabase

NewLibsql creates a new libsql database

func NewPostgres

func NewPostgres(dsn string) *SqlDatabase

NewPostgres creates a new postgres database

func NewSqlite

func NewSqlite(sqliteFolder ...string) *SqlDatabase

func (*SqlDatabase) Bun

func (d *SqlDatabase) Bun() *bun.DB

func (*SqlDatabase) Ctx

func (d *SqlDatabase) Ctx() context.Context

func (*SqlDatabase) Init

func (d *SqlDatabase) Init(debug bool)

func (*SqlDatabase) Stop

func (d *SqlDatabase) Stop()

type Storage

type Storage interface {
	Init(bool)
	Stop()
	Bun() *bun.DB
	Ctx() context.Context
}

type StorageConfig

type StorageConfig struct {
	Enabled bool
	Type    StorageType
	DSN     string
}

type StorageType

type StorageType uint8
const (
	StorageTypeLibsql StorageType = iota
	StorageTypeSqlite
	StorageTypePostgres
)

type TLSConfig

type TLSConfig struct {
	CertFile string
	KeyFile  string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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