pam

package module
v0.0.0-...-cef15d8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2015 License: Apache-2.0 Imports: 3 Imported by: 0

README

pam

POST API Mux

INSTALL
$ go get github.com/gogap/pam
USE
classic http server
package main

import (
    "io"
    "log"
    "net/http"

    "github.com/gogap/pam"
)

// hello world, the web server
func HelloServer(w http.ResponseWriter, req *http.Request) {
    io.WriteString(w, "hello "+req.Header.Get(pam.REQ_X_API)+"!\n")
}

func main() {
    m := pam.New("hello")

    m.Post("gogap.hello.test", http.HandlerFunc(HelloServer))

    http.Handle("/", m)
    err := http.ListenAndServe(":12345", nil)
    if err != nil {
        log.Fatal("ListenAndServe: ", err)
    }
}
martini http server
package main

import (
    "io"
    "net/http"

    "github.com/go-martini/martini"
    "github.com/gogap/pam"
)

// hello world, the web server
func HelloServer(w http.ResponseWriter, req *http.Request) {
    io.WriteString(w, "hello "+req.Header.Get(pam.REQ_X_API)+"!\n")
}

func main() {
    m := martini.Classic()

    apiMux := pam.New("hello")
    apiMux.Post("gogap.hello.test", http.HandlerFunc(HelloServer))

    m.Post("/hello", apiMux.APIMatcher())
    m.Get("/hello", func() string { return "GET from func" })

    m.Run()
}

$ curl -X POST -H "X-API: gogap.hello.test"  http://127.0.0.1:12345/hello
hello gogap.hello.test!

Documentation

Index

Constants

View Source
const (
	REQ_X_API = "X-API"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type PostAPIMux

type PostAPIMux struct {
	// contains filtered or unexported fields
}

func New

func New(appName string) *PostAPIMux

func (*PostAPIMux) APIMatcher

func (p *PostAPIMux) APIMatcher() martini.Handler

APIMatcher is for martini

func (*PostAPIMux) AppName

func (p *PostAPIMux) AppName() string

func (*PostAPIMux) Post

func (p *PostAPIMux) Post(apiName string, h http.Handler)

func (*PostAPIMux) ServeHTTP

func (p *PostAPIMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL