Skip to content

Jamlie/vodka

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vodka

Vodka is a lightweight abstraction over net/http to build HTTP services in Go. Vodka provides an easy way to build APIs, with good middleware support.

Install

go get github.com/Jamlie/vodka

Examples

package main

import (
    "log"
    "net/http"
    "strconv"

    "github.com/Jamlie/vodka"
    "github.com/Jamlie/vodka/middleware"
)

func main() {
    v := vodka.New()

    v.Use(middleware.Logger)
    v.Use(middleware.CORS)

    v.GET("/", func(c vodka.Context) { // /
        c.HTML(http.StatusOK, "<h1>Hello, Vodka</h1>")
    })

    v1 := v.Route("/api")

    v1.POST("/users/{id}", func(c vodka.Context) { // /api/users/{id}
        userId := c.Query("id")

        id, err := strconv.Atoi(userId)
        if err != nil {
            c.JSON(http.StatusBadRequest, map[string]string{
                "error": err.Error(),
            })
        }

        c.JSON(http.StatusOK, map[string]int{
            "id": id,
        })
    })

    log.Fatal(http.ListenAndServe(":8080", v)) // or log.Fatal(v.Start(":8080"))
}

About

A simple abstraction on top of net/http

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages