vega

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 43 Imported by: 0

README

Vega

Speed Up Your Development

Vega is a high-performance Go web framework designed for rapid application development. Built with speed and simplicity in mind.

Features

  • ⚡ Lightning-fast routing with Chi
  • 🔐 Built-in authentication & session management
  • 📧 Email support (SMTP + APIs)
  • 💾 Multiple database support (PostgreSQL, MySQL)
  • 🗄️ Caching (Redis, Badger)
  • 📝 Template rendering (Jet, Go templates)
  • 🛡️ Security features (CSRF, encryption)
  • 🚀 CLI tool for scaffolding
  • 📦 Database migrations
  • ⏰ Cron job scheduler

Installation

Framework
go get github.com/sadvilkar-kiran/vega
CLI Tool
go install github.com/sadvilkar-kiran/vega/cmd/vega@latest

After installation, you can use the vega command:

vega new myapp
vega help

Quick Start

package main

import (
    "log"
    "os"
    
    "github.com/sadvilkar-kiran/vega"
)

func main() {
    path, err := os.Getwd()
    if err != nil {
        log.Fatal(err)
    }

    // Initialize Vega
    v := &vega.Vega{}
    err = v.New(path)
    if err != nil {
        log.Fatal(err)
    }

    v.AppName = "myapp"

    // Add your routes
    v.Routes.Get("/", func(w http.ResponseWriter, r *http.Request) {
        v.Render.Page(w, r, "home", nil, nil)
    })

    // Start server
    v.ListenAndServe()
}

Documentation

Full documentation coming soon. For now, check the source code and examples.

License

MIT License - see LICENSE file

Author

Kiran Sadvilkar

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database struct {
	DataType string
	Pool     *sql.DB
}

Database holds the database connection pool and type

type Encryption

type Encryption struct {
	Key []byte
}

Encryption provides encryption and decryption functionality

func (*Encryption) Decrypt

func (e *Encryption) Decrypt(cryptoText string) (string, error)

Decrypt decrypts encrypted text using AES decryption

func (*Encryption) Encrypt

func (e *Encryption) Encrypt(text string) (string, error)

Encrypt encrypts text using AES encryption

type Server

type Server struct {
	ServerName string
	Port       string
	Secure     bool
	URL        string
}

Server holds server configuration

type Validation

type Validation struct {
	Data   url.Values
	Errors map[string]string
}

Validation provides form validation functionality

func (*Validation) AddError

func (v *Validation) AddError(key, message string)

AddError adds an error message for a field

func (*Validation) Check

func (v *Validation) Check(ok bool, key, message string)

Check adds an error if the condition is false

func (*Validation) Has

func (v *Validation) Has(field string, r *http.Request) bool

Has checks if a field exists in the request

func (*Validation) IsDateISO

func (v *Validation) IsDateISO(field, value string)

IsDateISO validates that a value is a date in ISO format (YYYY-MM-DD)

func (*Validation) IsEmail

func (v *Validation) IsEmail(field, value string)

IsEmail validates that a value is a valid email address

func (*Validation) IsFloat

func (v *Validation) IsFloat(field, value string)

IsFloat validates that a value is a floating point number

func (*Validation) IsInt

func (v *Validation) IsInt(field, value string)

IsInt validates that a value is an integer

func (*Validation) NoSpaces

func (v *Validation) NoSpaces(field, value string)

NoSpaces validates that a value contains no whitespace

func (*Validation) Required

func (v *Validation) Required(r *http.Request, fields ...string)

Required validates that fields are not empty

func (*Validation) Valid

func (v *Validation) Valid() bool

Valid returns true if there are no validation errors

type Vega

type Vega struct {
	AppName  string
	Debug    bool
	Version  string
	ErrorLog *log.Logger
	InfoLog  *log.Logger
	RootPath string
	Routes   *chi.Mux
	Render   *render.Render
	Session  *scs.SessionManager
	DB       Database
	JetViews *jet.Set

	EncryptionKey string
	Cache         cache.Cache
	Scheduler     *cron.Cron
	Mail          mailer.Mail
	Server        Server
	// contains filtered or unexported fields
}

Vega is the overall type for the Vega package. Members that are exported in this type are available to any application that uses it.

func (*Vega) BuildDSN

func (v *Vega) BuildDSN() string

BuildDSN builds the datasource name for our database, and returns it as a string

func (*Vega) CreateDirIfNotExist

func (v *Vega) CreateDirIfNotExist(path string) error

CreateDirIfNotExist creates a new directory if it does not exist

func (*Vega) CreateFileIfNotExists

func (v *Vega) CreateFileIfNotExists(path string) error

CreateFileIfNotExists creates a new file at path if it does not exist

func (*Vega) DownloadFile

func (v *Vega) DownloadFile(w http.ResponseWriter, r *http.Request, pathToFile, fileName string) error

DownloadFile downloads a file

func (*Vega) Error404

func (v *Vega) Error404(w http.ResponseWriter, r *http.Request)

Error404 returns page not found response

func (*Vega) Error500

func (v *Vega) Error500(w http.ResponseWriter, r *http.Request)

Error500 returns internal server error response

func (*Vega) ErrorForbidden

func (v *Vega) ErrorForbidden(w http.ResponseWriter, r *http.Request)

ErrorForbidden returns a forbidden status message (client is known)

func (*Vega) ErrorStatus

func (v *Vega) ErrorStatus(w http.ResponseWriter, status int)

ErrorStatus returns a response with the supplied http status

func (*Vega) ErrorUnauthorized

func (v *Vega) ErrorUnauthorized(w http.ResponseWriter, r *http.Request)

ErrorUnauthorized sends an unauthorized status (client is not known)

func (*Vega) Init

func (v *Vega) Init(p initPaths) error

Init creates necessary folders for our Vega application

func (*Vega) ListenAndServe

func (v *Vega) ListenAndServe()

ListenAndServe starts the web server

func (*Vega) LoadTime

func (v *Vega) LoadTime(start time.Time)

LoadTime calculates function execution time. To use, add defer v.LoadTime(time.Now()) to the function body

func (*Vega) MigrateDownAll

func (v *Vega) MigrateDownAll(dsn string) error

MigrateDownAll rolls back all migrations

func (*Vega) MigrateForce

func (v *Vega) MigrateForce(dsn string) error

MigrateForce forces the migration version

func (*Vega) MigrateUp

func (v *Vega) MigrateUp(dsn string) error

MigrateUp runs all pending migrations

func (*Vega) New

func (v *Vega) New(rootPath string) error

New reads the .env file, creates our application config, populates the Vega type with settings based on .env values, and creates necessary folders and files if they don't exist

func (*Vega) NoSurf

func (v *Vega) NoSurf(next http.Handler) http.Handler

NoSurf adds CSRF protection to all POST requests

func (*Vega) OpenDB

func (v *Vega) OpenDB(dbType, dsn string) (*sql.DB, error)

OpenDB opens a connection to a sql database. dbType must be one of postgres (or pgx). TODO: add support for mysql/mariadb

func (*Vega) RandomString

func (v *Vega) RandomString(n int) string

RandomString generates a random string length n from values in the const randomString

func (*Vega) ReadJSON

func (v *Vega) ReadJSON(w http.ResponseWriter, r *http.Request, data interface{}) error

ReadJSON reads JSON from request body into data

func (*Vega) SessionLoad

func (v *Vega) SessionLoad(next http.Handler) http.Handler

SessionLoad loads and saves session data for requests

func (*Vega) Steps

func (v *Vega) Steps(n int, dsn string) error

Steps runs n migration steps (positive for up, negative for down)

func (*Vega) Validator

func (v *Vega) Validator(data url.Values) *Validation

Validator creates a new validation instance

func (*Vega) WriteJSON

func (v *Vega) WriteJSON(w http.ResponseWriter, status int, data interface{}, headers ...http.Header) error

WriteJSON writes json from arbitrary data

func (*Vega) WriteXML

func (v *Vega) WriteXML(w http.ResponseWriter, status int, data interface{}, headers ...http.Header) error

WriteXML writes xml from arbitrary data

Directories

Path Synopsis
cmd
vega command

Jump to

Keyboard shortcuts

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