百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
K

kago

> 数据库
开源

KaGo

183 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

KaGo

Join our discussions here

KaGo Web Framework (not maintained anymore)

If you like Kago you will love Korm, this package will not be supported soon

Korm or Kmux or Ksbus are more composable, faster, and more powerful :

  • Kmux is faster using combination of safemap and radix tree , also it does not have param routing conflicts, you can have /test/user and /test/:table, if exact route match for the first , the request handled only by the first , otherwise if something like /test/something -> /test/:table

  • Kmux also can generate swagger docs from you code or from comments

  • Ksbus and Korm are perfect combination, allowing you to sync your servers and clients python and javascript all togethers

KaGo is a Django like web framework, that encourages clean and rapid development.

You can start a new project using 2 lines of code, run a high performance server with CRUD Admin Dashboard, interactive shell, easy and performant ORM, AutoSSL and lots more...

List of packages extracted from kago in order to make it more composable :

  • ORM Korm
  • Router Kmux
  • Network KSbus
  • Safemap Kmap
  • EnvLoader Kenv

Quick List of latest features :

  • NEW : Handle Many To Many relationship
  • NEW : orm.AutoMigrate generate query to file instead of executing it directly, you can execute it later using go run main.go shell -> migrate
  • NEW : orm.AddTrigger and orm.DropTrigger, examples
  • NEW : Admin Search and OrderBy
  • NEW : Auto SSL Letsencrypt Certificates and keep them up to date (auto renew 1 month before expire)
  • BareBone Mode Router Only
  • ORM handle coakroachdb in addition to sqlite, postgres, mysql and mariadb (check Performance at the bottom of this readme)
  • Watcher/Auto-Reloader
  • orm.AutoMigrate will handle all your migrations from a struct model, if you remove a field from the migrated struct, you will be prompted to do the migration, it can handle foreign_keys,many to many, checks, indexes,...
  • Fully editable CRUD Admin Dashboard (assets folder)
  • Realtime Logs at /logs running with flag go run main.go --logs
  • Convenient Router that handle params with regex type checking, Websockets and SSE protocols also
  • Interactive Shell go run main.go shell
  • Maybe the easiest ORM and SQL builder using go generics (working with sqlite, mysql,postgres and coakroach)
  • OpenApi docs at /docs running with flag go run main.go --docs with dedicated package docs to help you manipulate docs.json file
  • AES encryption for authentication sessions using package encryptor
  • Argon2 hashing using package hash
  • EnvLoader the fastest package envloader to load directly env to struct
  • Internal Eventbus using go routines and channels (very powerful), use cases are endless
  • Monitoring Prometheus/grafana /metrics running with flag go run main.go --monitoring
  • Profiler golang official debug pprof /debug/pprof/(heap|profile\trace) running with flag go run main.go --profiler
  • Embed your application static and template files
  • Ready to use Progressive Web App Support (pure js, without workbox)

Join our discussions here


Installation

get the last version
bash
go get -u github.com/kamalshkeir/[email protected]

Drivers moved outside this package to not get them all in your go.mod file

bash
go get github.com/kamalshkeir/sqlitedriver
go get github.com/kamalshkeir/pgdriver
go get github.com/kamalshkeir/mysqldriver

Quick start

Router + Admin + Database + Shell
go
package main

import (
	"github.com/kamalshkeir/kago"
	"github.com/kamalshkeir/sqlitedriver"
	"github.com/kamalshkeir/mysqldriver"
	"github.com/kamalshkeir/pgdriver"
)

func main() {
	sqlitedriver.Use() // use one of this drivers
	mysqldriver.Use()
	pgdriver.Use()
	app := kago.New() // router + admin + database + shell
	app.Run()
}

BareBone Router (no assets cloned)

go
package main

import (
	"github.com/kamalshkeir/kago"
)

func main() {
	app := kago.BareBone() // router only, bot need for sql drivers
	app.Run()
}

1- running 'go run main.go' the first time, will clone assets folder if run with kago.New and will not if run using kago.BareBone

bash
go run main.go

2- create super user

bash
go run main.go shell    

-> createsuperuser

3- Run the server:

bash
# run localy:
go run main.go # default: -h localhost -p 9313

That's it, you can visit /admin


Run HTTPS letsencrypt in production using env vars and tags

if you have already certificates
bash
go run main.go -h example.com -p 443 --cert cerkey.pem --key privkey.pem
Autocerts (certs generated and renewed automatically) :
bash
go run main.go -h example.com -p 443 
# this will generate 2 certificates from letsencrypt example.com and www.example.com to directory ./certs
to add more domains, you can use tag 'domains':
bash
go run main.go -h example.com -p 443 -domains a.example.com, b.example.com,... 
bash
# most important tags and env vars that you can override:
HOST         -h            DEFAULT: "localhost"
PORT         -p			   DEFAULT: "9313"
DOMAINS      -domains	   DEFAULT: ""
CERT 	     -cert         DEFAULT: ""
KEY 	     -key          DEFAULT: ""
PROFILER     -profiler     DEFAULT: false
DOCS         -docs         DEFAULT: false
LOGS         -logs         DEFAULT: false
MONITORING   -monitoring   DEFAULT: false

Watcher or Auto-reloader

install

bash
go install github.com/kamalshkeir/kago/cmd/katcher

or get the binary from releases

Then you can run:

bash
katcher --root ${PWD} (will watch all files at root)
katcher --root ${PWD} --watch assets/templates,assets/static (will watch only '${PWD}/assets/templates' and '${PWD}/assets/static' folders)

Generated Admin Dashboard

an easy way to create your own theme, is to modify files inside assets , upload the assets folder into a repo and set these 2 values:
bash
settings.REPO_USER="YOUR_REPO_USER" // default kamalshkeir
settings.REPO_NAME="YOUR_REPO_NAME" // default kago-assets
you can easily override any handler of any url by creating a new one with the same method and path.

for example, to override the handler at GET /admin/login:

go
app.GET("/admin/login",func(c *kamux.Context) {
	...
})
// this will add another handler, and remove the old one completely 
// so it is very safe to do it this way also

Admin + PWA default handlers

…

Admin Search


Routing

Using GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, HandlerFunc

…

Websockets + Server Sent Events

After this one, you will stop being afraid to try websockets everywhere

…

Server Sent Events

go
func main() {
	app := kago.New()
	
	// will be hitted every 1-2 sec, you can check anything if change and send data on the fly using c.StreamResponse
	app.SSE("/sse/logs",func(c *kamux.Context) {
		lenStream := len(logger.StreamLogs)
		if lenStream > 0 {
			lastOne := lenStream-1
			err := c.StreamResponse(logger.StreamLogs[lastOne])
			if err == nil{
				logger.StreamLogs=[]string{}
			}
		}
	})
	
	app.Run()
}

Parameters (path + query)

…

Context Http

There is also WsContext seen above
…

Multipart/Urlencoded Form

go
func main() {
	app := kago.New()

	app.POST("/ajax", func(c *kamux.Context) {
        // get json body to map[string]any
		requestData := c.BodyJson()
        if email,ok := requestData["email"]; ok {
            ...
        }

        if err != nil {
            c.Status(400).Json(kamux.M{
			    "error":"User doesn not Exist",
		    })
        }
	})
	app.Run()
}

Upload file

…

Middlewares

Global server middlewares

…

Handler middlewares

go
// USAGE:
r.GET("/admin", kamux.Admin(IndexView)) // will check from session cookie if user.is_admin is true
r.GET("/admin/login",kamux.Auth(LoginView)) // will get session from cookies decrypt it and validate it
r.GET("/test",kamux.BasicAuth(LoginView,"username","password"))

ORM

i waited go1.18 and generics to make this package orm to keep performance at it's best with convenient way to query your data, even from multiple databases

queries are cached using powerfull eventbus style that empty cache when changes in database may corrupt your data, so use it until you have a problem with it

to disable it :
orm.UseCache=false

Let's start by ways to add new database:

go
orm.NewDatabaseFromDSN(dbType,dbName string,dbDSN ...string) (error)
orm.NewDatabaseFromConnection(dbType,dbName string,conn *sql.DB) (error)
orm.GetConnection(dbName ...string) // GetConnection return default connection for orm.DefaultDatabase (if dbName not given or "" or "default") else it return the specified one
orm.UseForAdmin(dbName string) // UseForAdmin use specific database in admin panel if manymatched db
orm.ManyToMany(table1, table2 string, dbName ...string) error // create m2m_table1_table2 table relations

Utility database queries:

go
orm.GetAllTables(dbName ...string) []string // if dbName not given, .env used instead to default the db to get all tables in the given db
orm.GetAllColumnsTypes(table string, dbName ...string) map[string]string // clear i think
orm.CreateUser(email,password string,isAdmin int, dbName ...string) error // password will be hashed using argon2

Migrations

using the shell, you can migrate a .sql file go run main.go shell

OR

you can migrate from a struct using Auto Migrate

when kago app executed, all models registered using AutoMigrate will be synchronized with the database so if you add a field to you struct or add a column to your table, you will have a prompt proposing migration

execute AutoMigrate and don't think about it, it will handle all synchronisations between your project structs types like in the example Bookmark below

If you need to change a tag, remove the field, restart, put the new one with the new tag, restart again, that's it


Available Tags by struct field type and Examples :


#String Field:

Without parameter                 With parameter                           

*  	text (create column as TEXT not VARCHAR)
*  	notnull
*  	unique
*   iunique // insensitive unique
*  	index, +index, index+ (INDEX ascending)
*  	index-, -index (INDEX descending)
*  	default (DEFAULT '')
* 	default:'any' (DEFAULT 'any')
*	mindex:...
* 	uindex:username,Iemail // CREATE UNIQUE INDEX ON users (username,LOWER(email)) 
	// 	email is lower because of 'I' meaning Insensitive for email
* 	fk:...
* 	size:50  (VARCHAR(50))
* 	check:...

Int, Uint, Int64, Uint64 Fields:

Without parameter                

*   -  			 (To Ignore a field)
*   autoinc, pk  (PRIMARY K

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Goadmineventbusgenericsgo

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库