wabservar

BSD-3-CLAUSE License

Stars
10

WABSERVAR

WABSERVAR is an enterpise not ready HTTP web server on TCP sockets created during a hackathon.

Features:

  • no tests
  • no stability
  • no guarantees
  • open source
  • go modules
  • cool name
  • yolo

Additional Thank you to the Go team and net/http package 🎉

Example

package main

import (
	"errors"
	"strconv"
	"time"

	"github.com/cristaloleg/wabservar"
)

func main() {
	index := func(req *wabservar.Request) ([]byte, int, error) {
		req.Header.Add("Location", "http://www.wabservar.enterprise.com/index.asp")
		return nil, 301, nil
	}

	ping := func(req *wabservar.Request) ([]byte, int, error) {
		return nil, 200, nil
	}

	echo := func(req *wabservar.Request) ([]byte, int, error) {
		value, ok := req.Header.Get("X-Delay-Ms")
		if ok {
			v, _ := strconv.Atoi(value)
			time.Sleep(time.Duration(v) * time.Millisecond)
		}
		return []byte(req.Body), 200, nil
	}

	notFound := func(req *wabservar.Request) ([]byte, int, error) {
		return nil, 404, errors.New("well, path, not found")
	}

	m := wabservar.NewMux(notFound)
	m.AddRoute("GET", "/", index)
	m.AddRoute("POST", "/", index)
	m.AddRoute("GET", "/ping", ping)
	m.AddRoute("POST", "/echo", echo)

	s, _ := wabservar.NewServer(":31337", m)

	s.Run()
}
Badges
Extracted from project README
Build Status coverage PRs Welcome