• Stars
    star
    127
  • Rank 282,740 (Top 6 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A lightweight and fast http router from outer space

Alien Coverage Status Build Status GoDoc Go Report Card

Alien is a lightweight http router( multiplexer) for Go( Golang ), made for humans who don't like magic.

Documentation docs

Features

  • fast ( see the benchmarks, or run them yourself)
  • lightweight ( just a single file read all of it in less than a minute)
  • safe( designed with concurrency in mind)
  • middleware support.
  • routes groups
  • no external dependency( only the standard library )

Motivation

I wanted a simple, fast, and lightweight router that has no unnecessary overhead using the standard library only, following good practices and well tested code( Over 90% coverage)

Installation

go get github.com/gernest/alien

Usage

normal static routes

package main

import (
	"log"
	"net/http"

	"github.com/gernest/alien"
)

func main() {
	m := alien.New()
	m.Get("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("hello world"))
	})
	log.Fatal(http.ListenAndServe(":8090", m))
}

visiting your localhost at path / will print hello world

named params

package main

import (
	"log"
	"net/http"

	"github.com/gernest/alien"
)

func main() {
	m := alien.New()
	m.Get("/hello/:name", func(w http.ResponseWriter, r *http.Request) {
		p := alien.GetParams(r)
		w.Write([]byte(p.Get("name")))
	})
	log.Fatal(http.ListenAndServe(":8090", m))
}

visiting your localhost at path /hello/tanzania will print tanzania

catch all params

package main

import (
	"log"
	"net/http"

	"github.com/gernest/alien"
)

func main() {
	m := alien.New()
	m.Get("/hello/*name", func(w http.ResponseWriter, r *http.Request) {
		p := alien.GetParams(r)
		w.Write([]byte(p.Get("name")))
	})
	log.Fatal(http.ListenAndServe(":8090", m))
}

visiting your localhost at path /hello/my/margicl/sheeplike/ship will print my/margical/sheeplike/ship

middlewares

Middlewares are anything that satisfy the interface func(http.Handler)http.Handler . Meaning you have thousands of middlewares at your disposal, you can use middlewares from many golang http frameworks on alien(most support the interface).

package main

import (
	"log"
	"net/http"

	"github.com/gernest/alien"
)

func middleware(h http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("hello middlware"))
	})
}

func main() {
	m := alien.New()
	m.Use(middleware)
	m.Get("/", func(_ http.ResponseWriter, _ *http.Request) {
	})
	log.Fatal(http.ListenAndServe(":8090", m))
}

visiting your localhost at path / will print hello middleware

groups

You can group routes

package main

import (
	"log"
	"net/http"

	"github.com/gernest/alien"
)

func main() {
	m := alien.New()
	g := m.Group("/home")
	m.Use(middleware)
	g.Get("/alone", func(w http.ResponseWriter, _ *http.Request) {
		w.Write([]byte("home alone"))
	})
	log.Fatal(http.ListenAndServe(":8090", m))
}

visiting your localhost at path /home/alone will print home alone

Contributing

Start with clicking the star button to make the author and his neighbors happy. Then fork the repository and submit a pull request for whatever change you want to be added to this project.

If you have any questions, just open an issue.

Author

Geofrey Ernest @gernesti on twitter

Licence

MIT see LICENSE

More Repositories

1

utron

A lightweight MVC framework for Go(Golang)
Go
2,223
star
2

wow

๐Ÿ˜ฎโ—โ— Wowโ— now my Go commandline app is spinning with ๐ŸŒˆ and ๐Ÿด
Go
507
star
3

hero

[NO LONGER MAINTAINED} oauth 2 server implementation in Go
Go
213
star
4

greact

like preact, but for go with wasm
Go
146
star
5

apidemic

Fake JSON response server
Go
136
star
6

mention

Twitter like mentions and #hashtags parser for Go(Golang)
Go
107
star
7

ita

Go(Golang) library that provides a clean API for dynamically calling structs methods
Go
70
star
8

hot

smart golang templates
Go
61
star
9

front

extracts frontmatter from text files with ease with golang.
Go
55
star
10

qlql

Go
26
star
11

bongo

Elegant static website generation with Go
Go
26
star
12

orange

A lightweight Object Relational Mapper for Go
Go
22
star
13

mailchecker-go

Temporary (disposable/throwaway) email detection library in Go(Golang)
Go
20
star
14

zedlist

DEPRECATED
Go
20
star
15

helen

Handle your static assets with care
Go
18
star
16

zunicode

Zig
17
star
17

hoodie

pure zig language server with swagger and bling bling
Zig
17
star
18

kemi

Win at unpacking archive files with Go (golang)
Go
16
star
19

aurora

minimalistic social network, with bolt database and Go
Go
15
star
20

resingo

[UNMAINTAINED] Unofficial golang sdk for resin.io
Go
14
star
21

time

Zig
14
star
22

talk

What I think
Go
13
star
23

cute

material-ui components for gopherjs and vecty
Go
13
star
24

nutz

A cool way to work with bolt database buckets
Go
12
star
25

vectypresent

Go
12
star
26

base32

base32 encoding/decoding for ziglang
Zig
11
star
27

requiemdb

Pure Go Permanent Storage For Open Telemetry Metrics, Traces and Logs, based on Compressed Roaring B-Tree Bitmaps, using Typescript as Query Language
Go
10
star
28

mpesa-dev-api

Developer guide for M-PESA API
9
star
29

blue

JSON to Influxdb line protocol
Go
9
star
30

awesome-africa

Curated list of awesome projects made in Africa
7
star
31

qlstore

gorilla/sessions storage with embedded sql database( (ql)
Go
6
star
32

url

Zig
6
star
33

semver

4
star
34

frieren

Alternative to prometheus for open telemetry data in (development | testing | staging ) environments built on Compressed Roaring Bitmaps
Go
4
star
35

goo

Win at Go(Golang) with Go
Go
3
star
36

tt

Go
3
star
37

mad

Go
3
star
38

qlfu

Go
3
star
39

lora

A simple website hosting application
CSS
2
star
40

mrs

A user profile manager, with boltdb
Go
2
star
41

wuxia

Go
2
star
42

sequel

Extensible SQL Lexer and Parser for Go
Go
2
star
43

arrow3

Build apache arrow records from protocol buffers
Go
2
star
44

rbf

Go
2
star
45

blogdown

view github based project wiki offline
Ruby
2
star
46

gforms

forms library for golang
Go
2
star
47

gs

Go
1
star
48

adapi

Personal advertisment management API service
Go
1
star
49

classnames

Port of classnames node module to gopherjs/vecty
Go
1
star
50

matrix

Go
1
star
51

glory

millitary grade amunition for your Go web development
Go
1
star
52

trib

Go
1
star
53

sweetjesus

Web backend for M-PESA processing
Go
1
star
54

tafuta

Go
1
star
55

zanzibar

An experimental build tool based oon Go templates.
Go
1
star
56

roaring

Go
1
star
57

rows

Go
1
star
58

jsonrpc2

Zig
1
star
59

image.zig

Image library for zig
Zig
1
star
60

pablo

Build and publish your book
Go
1
star
61

vscode-moon

TypeScript
1
star
62

wudl

Go
1
star
63

bearcub

Go
1
star
64

riddick

Pure Go .DS_Store file reader/writter
Go
1
star
65

legend

Legend of microservices
Go
1
star
66

laisense

Lincense inspector for Go(Golang) project
Go
1
star
67

lily.vim

vim syntax highlighting for lily programming language https://github.com/jesserayadkins/lily
Vim Script
1
star
68

go-wasm-server

JavaScript
1
star