gotuna

package module
v0.0.1-beta Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: MIT Imports: 15 Imported by: 8

README

GoTuna - progressive web framework written in Go

NOTE: This project is under heavy development and is not ready for use.

Features

  • MVC pattern
  • Router (Gorilla)
  • Middleware support
  • Session managment (Gorilla)
  • User authentication (via user provider interface)
  • Native view rendering (html/template)
  • Multi-language support

Requirements

  • Make sure you have Go >= 1.16 installed

Testing

go test -race -v ./...

Running examples

go run examples/fullapp/cmd/main.go

External dependencies

External modules are mostly used when the feature is too complex to build or maintain - Router, Secure cookies

TODO

  • Validation (input/forms)
  • Cache

Licence

This project is licensed under the MIT License.

Documentation

Index

Constants

View Source
const CORSAllowedMethods = "OPTIONS,HEAD,GET,POST,PUT,PATCH,DELETE"
View Source
const CORSAllowedOrigin = "*"
View Source
const ContentTypeHTML = "text/html; charset=utf-8"
View Source
const UserIDKey = "_user_id"
View Source
const UserLocaleKey = "_user_locale"

Variables

This section is empty.

Functions

func ContextWithUser

func ContextWithUser(ctx context.Context, user User) context.Context

func TypeFromString

func TypeFromString(raw string, t interface{}) error

func TypeToString

func TypeToString(t interface{}) (string, error)

Types

type App

type App struct {
	Logger         *log.Logger
	Router         *mux.Router
	Static         fs.FS
	StaticPrefix   string
	ViewFiles      fs.FS
	ViewHelpers    []ViewHelperFunc
	Session        *Session
	UserRepository UserRepository
	Locale         Locale
}

func (App) Authenticate

func (app App) Authenticate(destination string) mux.MiddlewareFunc

func (App) Cors

func (app App) Cors() mux.MiddlewareFunc

func (App) Logging

func (app App) Logging() mux.MiddlewareFunc

func (App) NewTemplatingEngine

func (app App) NewTemplatingEngine() TemplatingEngine

func (App) Recoverer

func (app App) Recoverer(destination string) mux.MiddlewareFunc

func (App) RedirectIfAuthenticated

func (app App) RedirectIfAuthenticated(destination string) mux.MiddlewareFunc

func (App) ServeFiles

func (app App) ServeFiles(notFound http.Handler) http.Handler

func (App) StoreUserToContext

func (app App) StoreUserToContext() mux.MiddlewareFunc

type FlashMessage

type FlashMessage struct {
	Message   string
	Kind      string
	AutoClose bool
}

func NewFlash

func NewFlash(message string) FlashMessage

type InMemoryUser

type InMemoryUser struct {
	UniqueID string
	Email    string
	Name     string
	Password string
}

func (InMemoryUser) GetID

func (u InMemoryUser) GetID() string

type Locale

type Locale interface {
	T(language string, s string, p ...interface{}) string
	TP(language string, s string, n int, p ...interface{}) string
}

func NewLocale

func NewLocale(set map[string]map[string]string) Locale

type Session

type Session struct {
	Store sessions.Store
}

func NewSession

func NewSession(store sessions.Store) *Session

NewSession returns new session with requested store

func (Session) Delete

func (s Session) Delete(w http.ResponseWriter, r *http.Request, key string) error

func (Session) Destroy

func (s Session) Destroy(w http.ResponseWriter, r *http.Request) error

func (Session) Flash

func (s Session) Flash(w http.ResponseWriter, r *http.Request, flashMessage FlashMessage) error

func (Session) Flashes

func (s Session) Flashes(w http.ResponseWriter, r *http.Request) []FlashMessage

func (Session) Get

func (s Session) Get(r *http.Request, key string) (string, error)

func (Session) GetUserID

func (s Session) GetUserID(r *http.Request) (string, error)

func (Session) GetUserLocale

func (s Session) GetUserLocale(r *http.Request) string

func (Session) IsGuest

func (s Session) IsGuest(r *http.Request) bool

func (Session) Put

func (s Session) Put(w http.ResponseWriter, r *http.Request, key string, value string) error

func (Session) SetUserID

func (s Session) SetUserID(w http.ResponseWriter, r *http.Request, id string) error

func (Session) SetUserLocale

func (s Session) SetUserLocale(w http.ResponseWriter, r *http.Request, id string) error

type TemplatingEngine

type TemplatingEngine interface {
	Render(w http.ResponseWriter, r *http.Request, patterns ...string)
	Set(key string, data interface{}) TemplatingEngine
	SetError(errorKey, description string) TemplatingEngine
	GetErrors() map[string]string
}

type User

type User interface {
	GetID() string
}

func GetUserFromContext

func GetUserFromContext(ctx context.Context) (User, error)

type UserRepository

type UserRepository interface {
	Authenticate(w http.ResponseWriter, r *http.Request) (User, error)
	GetUserByID(id string) (User, error)
}

func NewInMemoryUserRepository

func NewInMemoryUserRepository(users []InMemoryUser) UserRepository

type ViewHelperFunc

type ViewHelperFunc func(w http.ResponseWriter, r *http.Request) (string, interface{})

Directories

Path Synopsis
examples
basic/cmd command
fullapp/cmd command
test

Jump to

Keyboard shortcuts

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