flint

package module
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2025 License: MIT Imports: 32 Imported by: 0

README

Flint Logo

Flint

A blazing fast and lightweight web framework for Go.

Docs

Telegram Channel

Telegram Turkey Channel

X

YouTube


⚡️ What is Flint?

Flint is a simple and minimal backend framework written in Go, made for fast API development with clean structure and easy usage.

🐾 Flinex

Flint Mascot

🚀 Quick Start

go get github.com/coderianx/flint
package main

import "github.com/coderianx/flint"

func main() {
    app := flint.NewServer()

    app.Handle("/", func(ctx flint.Context) {
        ctx.String("Hello from Flint!")
    })

    app.Run(":8080")
}

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Built with ❤️ using Go

Documentation

Overview

router.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Argon2Hash

func Argon2Hash(password string) (string, error)

func Argon2Verify

func Argon2Verify(password, encodedHash string) (bool, error)

func Bcrypt

func Bcrypt(password string, optionalCost ...int) string

func Blake2b

func Blake2b(data string) string

func Blake2s

func Blake2s(data string) string

func CompareBcrypt

func CompareBcrypt(password, hashed string) bool

func CreateLogFile

func CreateLogFile(fileName string) error

func FakeData

func FakeData(filename string, count int, format string)

FakeData generates fake users and saves as JSON or CSV.

func FakeDataDB added in v1.4.2

func FakeDataDB(filename string, count int)

FakeDataDB creates/opens a sqlite database file (modernc.org/sqlite) and inserts `count` fake users. filename: path to .db file (e.g. "users.db") count: number of fake users to insert

func Info

func Info()

func LogError

func LogError(function string, message string)

func Md5

func Md5(args ...string) string

func Sha256

func Sha256(args ...string) string

func Sha3_256

func Sha3_256(args ...string) string

func Sha3_512

func Sha3_512(args ...string) string

func Sha512

func Sha512(args ...string) string

func Version

func Version()

Types

type Context

type Context struct {
	Writer  http.ResponseWriter
	Request *http.Request
	Params  map[string]string
}

Context represents the context of a single HTTP request in the Flint framework. It provides convenient access to the request data, query parameters, form values, HTTP method checks, and response writers for sending various types of responses. By using Context, developers can easily read input from the client, write output, handle JSON, files, HTML templates, and manage redirects or errors in a structured way.

func (*Context) Default404

func (c *Context) Default404()

func (*Context) Default405 added in v1.2.0

func (c *Context) Default405()

func (*Context) Delete

func (c *Context) Delete() bool

Delete returns true if the current request method is DELETE.

func (*Context) File

func (c *Context) File(filepath string)

File serves a file from the given file path to the client.

func (*Context) FormArgon2 added in v1.2.0

func (c *Context) FormArgon2(key string) string

It automatically hashes the data received from the form with Argon2.

func (*Context) FormBcrypt

func (c *Context) FormBcrypt(key string) string

Automatically hashes the data received from the form with Bcrypt

func (*Context) FormBool added in v1.4.2

func (c *Context) FormBool(key string) bool

FormBool returns the value of a form field as a boolean. Accepts values like "true", "1", "yes" → true and "false", "0", "no" → false. Defaults to false if invalid.

func (*Context) FormData

func (c *Context) FormData(key string) string

FormData returns the value of a form field for the given key. It reads the data from POST or PUT form submissions.

func (*Context) FormFile

func (c *Context) FormFile(key string) (multipart.File, *multipart.FileHeader, error)

FormFile retrieves the uploaded file and its header from a multipart form for the given form key. It returns the file, its header, and an error if the file cannot be found or opened

func (*Context) FormFloat added in v1.4.2

func (c *Context) FormFloat(key string) float64

FormFloat returns the value of a form field as a float64. If the conversion fails, it logs the error and returns 0.0.

func (*Context) FormInt

func (c *Context) FormInt(key string) int

FormInt returns the value of a form field as an integer for the given key. If the conversion fails, it logs the error and returns 0.

func (*Context) FormMD5

func (c *Context) FormMD5(key string) string

Hashes the data received from the form with MD5 and returns it.

func (*Context) FormSHA256

func (c *Context) FormSHA256(key string) string

Hashes the data received from the form with Sha256 and returns it.

func (*Context) FormSHA512

func (c *Context) FormSHA512(key string) string

Hashes the data received from the form with Sha512 and returns it.

func (*Context) Get

func (c *Context) Get() bool

Get returns true if the current request method is GET.

func (*Context) HTML

func (c *Context) HTML(status int, tmplPath string, data interface{})

func (*Context) HTMLString added in v1.3.2

func (c *Context) HTMLString(status int, html_code string)

HTMLString writes the given HTML string directly to the response with the specified HTTP status code.

func (*Context) JSON

func (c *Context) JSON(status int, data interface{})

JSON encodes the given data as JSON and writes it to the response with the specified HTTP status code.

func (*Context) JSONFile added in v1.3.1

func (c *Context) JSONFile(status int, filepath string)

JSONFile serves a JSON file from the given file path with the specified HTTP status code. Returns 404 if the file is not found.

func (*Context) JSONPretty added in v1.3.1

func (c *Context) JSONPretty(status int, data interface{}, indent ...int)

JSONPretty encodes the given data as pretty-printed JSON and writes it to the response with the specified HTTP status code. Optional indent size can be provided.

func (*Context) Param added in v1.3.2

func (c *Context) Param(key string) string

Param returns the path parameter value for the given key.

func (*Context) ParamInt added in v1.3.2

func (c *Context) ParamInt(key string) (int, error)

func (*Context) ParamIntDefault added in v1.3.2

func (c *Context) ParamIntDefault(key string, defaultVal int) int

func (*Context) Post

func (c *Context) Post() bool

Post returns true if the current request method is POST.

func (*Context) Put added in v1.2.0

func (c *Context) Put() bool

Put returns true if the current request method is PUT.

func (*Context) Query added in v1.1.0

func (c *Context) Query(key string) string

Query returns the query parameter value for the given key.

func (*Context) QueryBool added in v1.3.1

func (c *Context) QueryBool(key string, defaultVal bool) bool

func (*Context) QueryFloat added in v1.1.0

func (c *Context) QueryFloat(key string, defaultVal float64) float64

func (*Context) QueryInt added in v1.1.0

func (c *Context) QueryInt(key string) (int, error)

func (*Context) QueryIntDefault added in v1.1.0

func (c *Context) QueryIntDefault(key string, defaulVal int) int

func (*Context) Redirect

func (c *Context) Redirect(status int, format string, args ...interface{})

Redirect sends an HTTP redirect to the specified URL with the given status code. Commonly used status codes are 302 (Found), 301 (Moved Permanently), and 307/308.

func (*Context) String

func (c *Context) String(status int, text string)

String writes a plain string to the response with the specified HTTP status code.

func (*Context) Stringf added in v1.1.0

func (c *Context) Stringf(status int, text string, a ...any)

Stringf writes a formatted string to the response with the specified HTTP status code.

func (*Context) Template404

func (c *Context) Template404(templatePath string, data ...any)

func (*Context) Template405 added in v1.2.0

func (c *Context) Template405(templatePath string, data ...any)

func (*Context) UserAgent added in v1.2.0

func (c *Context) UserAgent() string

UserAgent returns the User-Agent header from the request.

func (*Context) XML added in v1.3.2

func (c *Context) XML(status int, data interface{})

XML serializes the provided Go data structure into XML and writes it as the response. The response Content-Type is set to application/xml. This is typically used for sending dynamic XML generated from structs.

func (*Context) XMLFile added in v1.3.2

func (c *Context) XMLFile(status int, filepath string)

XMLFile reads an XML file from the given filepath and writes it as the response. If the file cannot be found, it returns a 404 Not Found error. This is typically used for serving static XML files like sitemap.xml

func (*Context) XMLPretty added in v1.3.2

func (c *Context) XMLPretty(status int, data interface{})

XMLPretty serializes the provided Go data structure into a pretty-printed XML and writes it as the response with indentation for readability.

type Database added in v1.4.2

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

func Sqlite3 added in v1.4.2

func Sqlite3(path string) *Database

New Sqlite3 Database

func (*Database) Begin added in v1.4.2

func (d *Database) Begin() *sql.Tx

Transaction başlat

func (*Database) Column added in v1.4.2

func (d *Database) Column(name, typ string)

Add Column

func (*Database) Commit added in v1.4.2

func (d *Database) Commit(tx *sql.Tx)

Commit

func (*Database) Delete added in v1.4.2

func (d *Database) Delete(table string, criteria map[string]interface{})

Delete rows with criteria

func (*Database) DropTable added in v1.4.2

func (d *Database) DropTable(name string)

Delete Table

func (*Database) Execute added in v1.4.2

func (d *Database) Execute(query string, args ...interface{}) (sql.Result, error)

func (*Database) Exists added in v1.4.2

func (d *Database) Exists(table string, criteria map[string]interface{}) bool

Check if a row exists

func (*Database) Find added in v1.4.2

func (d *Database) Find(table, column string, value interface{}) []map[string]interface{}

Search with a single criterion

func (*Database) FindAll added in v1.4.2

func (d *Database) FindAll(table string) []map[string]interface{}

Read all data

func (*Database) Insert added in v1.4.2

func (d *Database) Insert(table string, data map[string]interface{})

Add Data

func (*Database) NewTable added in v1.4.2

func (d *Database) NewTable(name string, builder func(*Database))

Create New Table

func (*Database) Rollback added in v1.4.2

func (d *Database) Rollback(tx *sql.Tx)

Rollback

func (*Database) Truncate added in v1.4.2

func (d *Database) Truncate(table string)

Truncate table (delete all rows)

func (*Database) Update added in v1.4.2

func (d *Database) Update(table string, updates map[string]interface{}, whereColumn string, whereValue interface{})

Update işlemi (tek kriterli)

type Env added in v1.4.2

type Env struct{}

func EnvLoad added in v1.4.2

func EnvLoad(file string) *Env

func (*Env) GetBool added in v1.4.2

func (e *Env) GetBool(key string, defaults ...bool) bool

func (*Env) GetChar added in v1.4.2

func (e *Env) GetChar(key string, defaults ...string)

func (*Env) GetEnv added in v1.4.2

func (e *Env) GetEnv(key string, defaults ...string) string

func (*Env) GetFloat added in v1.4.2

func (e *Env) GetFloat(key string, defaults ...float64) float64

func (*Env) GetInt added in v1.4.2

func (e *Env) GetInt(key string, defaults ...int) int

type FakeUser

type FakeUser struct {
	ID        int       `json:"id"`
	Username  string    `json:"username"`
	Email     string    `json:"email"`
	Password  string    `json:"password"`
	HashedPwd string    `json:"hashed_password"`
	FullName  string    `json:"full_name"`
	Phone     string    `json:"phone"`
	Address   string    `json:"address"`
	Country   string    `json:"country"`
	CreatedAt time.Time `json:"created_at"`
}

FakeUser represents a fake user with extended fields.

type HandlerFunc

type HandlerFunc func(ctx *Context)

type Router

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

func NewRouter

func NewRouter() *Router

func (*Router) Handle

func (r *Router) Handle(method, path string, handler HandlerFunc)

Tüm methodlar için

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

stdlib uyumu: ServeHTTP

type Server

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

func NewServer

func NewServer() *Server

Create a new flint server

func (*Server) Delete added in v1.3.0

func (s *Server) Delete(path string, handler HandlerFunc)

DELETE

func (*Server) Get added in v1.3.0

func (s *Server) Get(path string, handler HandlerFunc)

GET

func (*Server) Handle

func (s *Server) Handle(path string, handler HandlerFunc)

Universal handler

func (*Server) Post added in v1.3.0

func (s *Server) Post(path string, handler HandlerFunc)

POST

func (*Server) Put added in v1.3.0

func (s *Server) Put(path string, handler HandlerFunc)

PUT

func (*Server) Run

func (s *Server) Run(addr ...string) error

Run Server

func (*Server) SetNotFound

func (s *Server) SetNotFound(handler HandlerFunc)

NotFound override

func (*Server) Static

func (s *Server) Static(routePath, dir string)

static file server

Directories

Path Synopsis
examples
basic command
basic/useragent command
register_app command
search command
simple_restapi command
test
run_test command

Jump to

Keyboard shortcuts

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