Skip to content
This repository has been archived by the owner on Jun 24, 2020. It is now read-only.

Foxcapades/go-midl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

midl

MIT License Build Status Codecov Go Report Card

Important

This repository is no longer maintained here.

It has been moved to github.com/vulpine-io/midl and all future updates will be done there.

Serializing middleware stack for building APIs in Go.

Install
$ go get gopkg.in/foxcapades/go-midl.v1/pkg/midl

Example

Simple

package main

import (
    "net/http"
    "gopkg.in/foxcapades/go-midl.v1/pkg/midl"
)

func main() {
    http.Handle("/", midl.JSONAdapter(
        NewSessionHandler(),
        NewInputValidator(),
        NewController(),
    ))
    log.Fatal(http.ListenAndServe(":8080", nil))
}

Working demo

Example usage using the demo available in the cmd/test package.

$ go run cmd/test/*.go &
$ curl -iX POST -d'{}' localhost:8080/combine
HTTP/1.1 400 Bad Request
Content-Type: application/json
Date: Tue, 29 May 2018 23:33:56 GMT
Content-Length: 51

["start: start is required","end: end is required"]
$ curl -iX POST -d'{"start":["a","b"], "end":["c","d"]}' localhost:8080/combine
HTTP/1.1 200 OK
Content-Type: application/json
Custom-Header: some value
Date: Tue, 29 May 2018 23:34:39 GMT
Content-Length: 32

{"combos":["ac","ad","bc","bd"]}

Testing

A full set of configurable mock implementations for every project interface is available in the gopkg.in/foxcapades/go-midl.v1/pkg/midlmock package.

About

Serializing middleware wrapper for go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages