Giter VIP home page Giter VIP logo

go-web's Introduction

Go Web GoDoc Travis CI Go Report Card

Go-web is a framework for micro web app development. Build web apps as microservices.

Overview

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 world. It wraps go-micro to give you service discovery, heartbeating and the ability to create web apps as microservices.

Features

  • Service Discovery
  • Heartbeating
  • Custom Handlers

Getting Started

Dependencies

Go-web makes use of go-micro which means it needs service discovery

See the go-micro for install instructions

For a quick start use consul

# install
brew install consul

# run
consul agent -dev

Usage

service := web.NewService(
	web.Name("example.com"),
)

service.HandleFunc("/foo", fooHandler)

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

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

Set 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)
)

Call Service

Go-web includes a http.Client with a custom http.RoundTripper that uses service discovery

c := service.Client()

rsp, err := c.Get("http://example.com/foo")

This will lookup service discovery for the service example.com and route to one of the available nodes.

go-web's People

Contributors

foobar2016 avatar gillesfabio avatar lipl2017 avatar nickjackson avatar st3v avatar syntaqx avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.