minimal

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: MIT Imports: 16 Imported by: 0

README

Minimal

Minimal is a small, opinionated wrapper around Echo and Gorm.
Postgres set up and ready to go.

Absolute minimal configuration for a development environment

//go:embed assets
var embeddedFiles embed.FS

func embedFS(fs embed.FS) http.FileSystem {
	return http.FS(fs)
}

func main() {
	config := minimal.DevelopmentConfig
	_ = fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=5432 sslmode=disable TimeZone=Europe/Oslo",
		"localhost",
		"postgres",
		"postgres",
		"tmp",
	)
	config.DSN = dsn

	s := minimal.New(config, []minimal.Provider{
		&BaseRoutes{},
	}, []any{})

	s.Init(embedFS(embeddedFiles))
}

Routes defined like this:

type BaseRoutes struct{}

func (br *BaseRoutes) Register(e *echo.Echo) {
	e.GET("/", func(c echo.Context) error {
		return c.Render(200, "assets/index.html", nil)
	})
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DevelopmentConfig = Config{
		DSN:             "",
		HttpPort:        80,
		AutoTLS:         false,
		Domains:         []string{},
		FriendlyLogging: true,
	}
)

Functions

func AddMiddlewares

func AddMiddlewares(e *echo.Echo)

func Logging

func Logging(e *echo.Echo, friendly bool)

Types

type Config

type Config struct {
	DSN string

	HttpPort uint

	// Whether to use ACME auto-tls.
	AutoTLS bool

	CertKeyPath        string
	CertPrivateKeyPath string

	// FriendlyLogging makes logging look nice instead of wrapping it into JSON.
	FriendlyLogging bool

	Domains []string
}

type Provider

type Provider interface {
	Register(e *echo.Echo)
}

type Server

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

func New

func New(config Config, routes []Provider, models []any) Server

New creates a minimal Server instance. This is a 'minimal' example of how to configure the library:

//go:embed assets
var embeddedFiles embed.FS

func embedFS(fs embed.FS) http.FileSystem {
	return http.FS(fs)
}

type BaseRoutes struct{}

func (br *BaseRoutes) Register(e *echo.Echo) {
	e.GET("/", func(c echo.Context) error {
		return c.Render(200, "assets/index.html", nil)
	})
}

func main() {
	config := server.DevelopmentConfig
	_ = fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=5432 sslmode=disable TimeZone=Europe/Oslo",
		"localhost",
		"postgres",
		"postgres",
		"tmp",
	)
	config.DSN = dsn

	s := server.New(config, []provider.RouteProvider{
		&BaseRoutes{},
	}, []any{})

	s.Init(embedFS(embeddedFiles))
}

func (*Server) Echo

func (s *Server) Echo() *echo.Echo

func (*Server) Init

func (s *Server) Init(fs http.FileSystem)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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