• Stars
    star
    127
  • Rank 273,015 (Top 6 %)
  • Language
    Go
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 1 year 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
505
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
147
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

talk

What I think
Go
13
star
22

cute

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

time

Zig
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
9
star
27

mpesa-dev-api

Developer guide for M-PESA API
9
star
28

blue

JSON to Influxdb line protocol
Go
9
star
29

awesome-africa

Curated list of awesome projects made in Africa
7
star
30

qlstore

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

url

Zig
6
star
32

semver

4
star
33

goo

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

tt

Go
3
star
35

mad

Go
3
star
36

qlfu

Go
3
star
37

lora

A simple website hosting application
CSS
2
star
38

mrs

A user profile manager, with boltdb
Go
2
star
39

wuxia

Go
2
star
40

blogdown

view github based project wiki offline
Ruby
2
star
41

gforms

forms library for golang
Go
2
star
42

adapi

Personal advertisment management API service
Go
1
star
43

classnames

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

matrix

Go
1
star
45

glory

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

trib

Go
1
star
47

sweetjesus

Web backend for M-PESA processing
Go
1
star
48

tafuta

Go
1
star
49

zanzibar

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

jsonrpc2

Zig
1
star
51

image.zig

Image library for zig
Zig
1
star
52

pablo

Build and publish your book
Go
1
star
53

vscode-moon

TypeScript
1
star
54

legend

Legend of microservices
Go
1
star
55

wudl

Go
1
star
56

bearcub

Go
1
star
57

riddick

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

laisense

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

gs

Go
1
star
60

lily.vim

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

go-wasm-server

JavaScript
1
star