web

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

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

Go to latest
Published: May 15, 2016 License: Apache-2.0 Imports: 15 Imported by: 0

README

Go Web GoDoc Travis CI Go Report Card

Go-web is a tiny HTTP web server library which leverages go-micro to create micro web services as first class citizens in a microservice ecosystem. It's merely a wrapper around registration, heartbeating and initialization of the go-micro client. In the future go-platform features may be included.

Getting Started

Prerequisites

Go-web uses a similar pattern to go-micro. Look at the go-micro readme for starting up the registry.

Usage
service := web.NewService(
	web.Name("go.micro.web.example"),
	web.Version("latest"),
)

service.HandleFunc("/foo", fooHandler)

if err := service.Init(); err != nil {
	log.Fatal(err)
}

if err := service.Run(); err != nil {
	log.Fatal(err)
}
Use your own Handler

You might have a preference for a HTTP handler, so use something else. This loses the ability to register endpoints in discovery but we'll fix that soon.

import "github.com/gorilla/mux"

r := mux.NewRouter()
r.HandleFunc("/", indexHandler)
r.HandleFunc("/objects/{object}", objectHandler)

service := web.NewService(
	web.Handler(r)
)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// For serving
	DefaultName    = "go-web"
	DefaultVersion = "latest"
	DefaultId      = uuid.NewUUID().String()
	DefaultAddress = ":0"

	// for registration
	DefaultRegisterTTL      = time.Minute
	DefaultRegisterInterval = time.Second * 30
)

Functions

This section is empty.

Types

type Option

type Option func(o *Options)

func Address

func Address(a string) Option

Address to bind to - host:port

func Advertise(a string) Option

The address to advertise for discovery - host:port

func Handler

func Handler(h http.Handler) Option

func Id

func Id(id string) Option

Unique server id

func Metadata

func Metadata(md map[string]string) Option

Metadata associated with the service

func Name

func Name(n string) Option

Server name

func RegisterInterval

func RegisterInterval(t time.Duration) Option

func RegisterTTL

func RegisterTTL(t time.Duration) Option

func Version

func Version(v string) Option

Version of the service

type Options

type Options struct {
	Name      string
	Version   string
	Id        string
	Metadata  map[string]string
	Address   string
	Advertise string

	RegisterTTL      time.Duration
	RegisterInterval time.Duration

	Handler http.Handler

	// Alternative Options
	Context context.Context
}

type Service

type Service interface {
	Init(opts ...Option) error
	Handle(pattern string, handler http.Handler)
	HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
	Run() error
}

func NewService

func NewService(opts ...Option) Service

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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