1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-01-17 17:44:30 +02:00
Jerry 93ba8cd0df
continue fix pre version go get bug that unknown v3.5.1 (#2188)
* 1.fix plugins go get bug.
2.update all mode.
3.add tidy tools

* continue fix pre version go get bug that unknown v3.5.1
2021-06-30 09:24:00 +01:00
..
2020-12-26 15:32:45 +00:00
2021-01-20 21:01:10 +00:00
2021-06-30 07:21:03 +01:00
2021-01-20 21:01:10 +00:00
2021-01-20 21:01:10 +00:00
2021-05-13 13:07:25 +01:00
2021-01-20 21:01:10 +00:00
2021-01-20 21:01:10 +00:00
2021-01-20 21:01:10 +00:00
2021-01-20 21:01:10 +00:00

HTTP Server

The HTTP Server is a go-micro.Server. It's a partial implementation which strips out codecs, transports, etc but enables you to create a HTTP Server that could potentially be used for REST based API services.

Usage

import (
	"net/http"

	"github.com/micro/go-micro/server"
	httpServer "github.com/asim/go-micro/plugins/server/http"
)

func main() {
	srv := httpServer.NewServer(
		server.Name("helloworld"),
	)

	mux := http.NewServeMux()
	mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(`hello world`))
	})

	hd := srv.NewHandler(mux)

	srv.Handle(hd)
	srv.Start()
	srv.Register()
}

Or as part of a service

import (
	"net/http"

	"github.com/asim/go-micro/v3"
	"github.com/micro/go-micro/server"
	httpServer "github.com/asim/go-micro/plugins/server/http"
)

func main() {
	srv := httpServer.NewServer(
		server.Name("helloworld"),
	)

	mux := http.NewServeMux()
	mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(`hello world`))
	})

	hd := srv.NewHandler(mux)

	srv.Handle(hd)

	service := micro.NewService(
		micro.Server(srv),
	)
	service.Init()
	service.Run()
}