Installation
Install the module with a single command:
go get github.com/guno1928/alos-http
ALOS HTTP's documented production runtime is Linux amd64. The native server path is built around a custom epoll event loop.
Requires Go 1.26 or later. That matches the module's current go.mod.
Quick Start
The fastest way to get a server running:
Create your project
mkdir myapp && cd myapp go mod init myapp go get github.com/guno1928/alos-http
Write your server
package main import ( "log" "github.com/guno1928/alos-http/core" ) func main() { s := core.New() s.Router.GET("/", func(req *core.Request, resp *core.Response) { resp.String("Hello from ALOS!") }) s.Router.Build() log.Fatal(s.ListenAndServe()) }
Run it
go run main.go
Your server is now running at http://localhost:80. On Linux amd64, ALOS serves requests through its custom epoll event-loop backend.
Plain HTTP Mode
For development or internal services, start a plain HTTP server with no TLS overhead:
s := core.New(core.Config{ Addr: ":8080", PlainHTTP: true, }) s.Router.GET("/", func(req *core.Request, resp *core.Response) { resp.JSON([]byte(`{"status":"ok"}`)) }) s.Router.Build() log.Fatal(s.ListenAndServe())
HTTPS & TLS
ALOS uses its own native TLS 1.3 serving path on the main Linux runtime. Older TLS 1.2/1.1 clients can still fall back through Go's crypto/tls compatibility path when needed. You can use manual certificates or auto-generate self-signed ones:
With Manual Certificates
s := core.New(core.Config{ Addr: ":443", TLSCertFile: "cert.pem", TLSKeyFile: "key.pem", }) s.Router.Build() log.Fatal(s.ListenAndServeTLS())
With Self-Signed Cert (Development)
s := core.New(core.Config{ Addr: ":443", }) s.Router.Build() log.Fatal(s.ListenAndServeTLS())
The self-signed cert is saved to .alos-cert.pem and .alos-key.pem and reused on subsequent runs.
Automatic Certificates (ACME)
ALOS integrates with Let's Encrypt for automatic, free TLS certificates. Just provide your email and domain names:
s := core.New(core.Config{ Addr: ":443", HTTPAddr: ":80", ACME: &core.ACMEConfig{ Email: "admin@example.com", Domains: []string{"example.com", "www.example.com"}, CacheDir: ".alos-certs", }, }) s.Router.Build() log.Fatal(s.ListenAndServeTLS())
What happens automatically:
- Certificates are obtained on first startup
- HTTP-01 challenges are served on port 80
- Certs are stored in
.alos-certs/directory - Auto-renewal runs every 6 hours, 30 days before expiry
- DNS validation ensures domains point to your server
Your First Routes
Register routes with the built-in router. ALOS supports all standard HTTP methods:
s.Router.GET("/hello", func(req *core.Request, resp *core.Response) { resp.String("Hello, World!") }) s.Router.GET("/users/:id", func(req *core.Request, resp *core.Response) { id := req.ParamValue("id") resp.JSON([]byte(`{"user":"` + id + `"}`)) }) s.Router.POST("/api/data", func(req *core.Request, resp *core.Response) { body := req.Body resp.Status(201).Bytes(body) }) s.Router.Build()
Redirects
s.Router.GET("/old-page", func(req *core.Request, resp *core.Response) { resp.Redirect("/new-page", 301) })
For more advanced routing, see the Routing documentation.
Adding Middleware
Apply middleware globally or per-group. ALOS includes several production-ready middleware:
s.Router.Use(core.Recovery()) s.Router.Use(core.Logger()) s.Router.Use(core.RealIP()) s.Router.Use(core.RequestID()) s.Router.Use(core.SecurityHeaders(core.DefaultSecurityHeaders())) s.SetCORS(core.CORSConfig{ AllowOrigins: []string{"*"}, AllowMethods: []string{"GET", "POST", "PUT", "DELETE"}, }) s.Router.Use(s.CORS.Middleware()) s.Router.Build()
ALOS also provides JWT authentication, session management, CSRF protection, and per-route rate limiting middleware. See the Middleware documentation for details.
For detailed middleware configuration, see the Middleware documentation.
JSON Responses
ALOS provides multiple ways to send JSON data:
Pre-built JSON
s.Router.GET("/api/status", func(req *core.Request, resp *core.Response) { resp.JSON([]byte(`{"status":"ok","version":"1.0"}`)) })
Auto-Marshal from Struct
type User struct { ID int `json:"id"` Name string `json:"name"` } s.Router.GET("/api/user", func(req *core.Request, resp *core.Response) { user := User{ID: 1, Name: "Alice"} resp.JSONMarshal(user) })
Parse JSON Request Body
The recommended approach is req.BindJSON, which unmarshals the request body into your struct in one call:
s.Router.POST("/api/users", func(req *core.Request, resp *core.Response) { var user User if err := req.BindJSON(&user); err != nil { resp.Status(400).JSON([]byte(`{"error":"invalid json"}`)) return } resp.Status(201).JSONMarshal(user) })
You can also use json.Unmarshal directly on req.Body if you prefer:
s.Router.POST("/api/users", func(req *core.Request, resp *core.Response) { var user User if err := json.Unmarshal(req.Body, &user); err != nil { resp.Status(400).JSON([]byte(`{"error":"invalid json"}`)) return } resp.Status(201).JSONMarshal(user) })
Complete Application
Putting it all together, a production-ready HTTPS server with routing, middleware, and JSON:
package main import ( "log" "github.com/guno1928/alos-http/core" ) func main() { s := core.New(core.Config{ Addr: ":8080", PlainHTTP: true, }) s.Router.Use(core.Recovery(), core.Logger(), core.Compress(core.CompressConfig{})) s.Router.GET("/", func(req *core.Request, resp *core.Response) { resp.String("Welcome to ALOS HTTP") }) s.Router.GET("/health", func(req *core.Request, resp *core.Response) { resp.JSON([]byte(`{"status":"ok"}`)) }) api := s.Router.Group("/api/v1", core.RealIP()) api.GET("/users/:id", func(req *core.Request, resp *core.Response) { id := req.ParamValue("id") resp.JSONMarshal(map[string]string{"id": id}) }) api.POST("/users", func(req *core.Request, resp *core.Response) { resp.Status(201).Bytes(req.Body) }) s.Router.NotFound(func(req *core.Request, resp *core.Response) { resp.Status(404).JSON([]byte(`{"error":"not found"}`)) }) s.Router.Build() log.Fatal(s.ListenAndServe()) }