Files
dependabot[bot] 59903e7662 Bump github.com/go-micro/plugins/v4/server/http from 1.2.1 to 1.2.2
Bumps [github.com/go-micro/plugins/v4/server/http](https://github.com/go-micro/plugins) from 1.2.1 to 1.2.2.
- [Release notes](https://github.com/go-micro/plugins/releases)
- [Commits](https://github.com/go-micro/plugins/compare/v4/logger/zap/v1.2.1...v4/server/http/v1.2.2)

---
updated-dependencies:
- dependency-name: github.com/go-micro/plugins/v4/server/http
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-08-31 09:39:15 +02:00
..
2023-04-19 20:24:34 +02:00
2023-04-19 20:24:34 +02:00
2023-04-19 20:24:34 +02:00
2023-04-19 20:24:34 +02:00
2023-04-19 20:24:34 +02:00
2023-04-19 20:24:34 +02:00
2023-04-19 20:24:34 +02:00
2023-04-19 20:24:34 +02: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/go-micro/plugins/v4/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"

	"go-micro.dev/v4"
	"github.com/micro/go-micro/server"
	httpServer "github.com/go-micro/plugins/v4/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()
}