Compare commits

..

5 Commits

Author SHA1 Message Date
ba292901d7 fixup build
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-05-09 21:14:55 +03:00
6d1b6c7014 allow to expose some method via http.HandlerFunc
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-05-09 21:13:11 +03:00
1276f99159 export Server to allow to cast
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-05-09 21:12:47 +03:00
ee5cbbbcb6 Merge pull request 'issue-155: add swagger-ui handler' (#157) from swaggerui into v3
Reviewed-on: #157
2023-05-04 06:51:42 +03:00
ce0abd2de3 issue-155: add swagger-ui handler
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-05-04 06:48:09 +03:00
22 changed files with 108 additions and 103 deletions

View File

@@ -9,8 +9,8 @@ to create a HTTP Server that could potentially be used for REST based API servic
import ( import (
"net/http" "net/http"
"go.unistack.org/micro/v4/server" "github.com/unistack-org/micro/v3/server"
httpServer "go.unistack.org/micro-server-http/v4" httpServer "github.com/unistack-org/micro-server-http"
) )
func main() { func main() {
@@ -37,9 +37,9 @@ Or as part of a service
import ( import (
"net/http" "net/http"
"go.unistack.org/micro/v4" "github.com/unistack-org/micro/v3"
"go.unistack.org/micro/v4/server" "github.com/unistack-org/micro/v3/server"
httpServer "go.unistack.org/micro-server-http/v4" httpServer "github.com/unistack-org/micro-server-http"
) )
func main() { func main() {

8
go.mod
View File

@@ -1,10 +1,10 @@
module go.unistack.org/micro-server-http/v4 module go.unistack.org/micro-server-http/v3
go 1.19 go 1.18
require ( require (
go.unistack.org/micro-proto/v4 v4.0.0 go.unistack.org/micro-proto/v3 v3.3.1
go.unistack.org/micro/v4 v4.0.1 go.unistack.org/micro/v3 v3.10.14
golang.org/x/net v0.7.0 golang.org/x/net v0.7.0
) )

13
go.sum
View File

@@ -48,14 +48,17 @@ github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/silas/dag v0.0.0-20211117232152-9d50aa809f35/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -65,10 +68,10 @@ github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.unistack.org/micro-proto/v4 v4.0.0 h1:+TAwKSlx48eLsNO2E2cO0JLE8we1KU2AuWe9Q310FuU= go.unistack.org/micro-proto/v3 v3.3.1 h1:nQ0MtWvP2G3QrpOgawVOPhpZZYkq6umTGDqs8FxJYIo=
go.unistack.org/micro-proto/v4 v4.0.0/go.mod h1:ArmK7o+uFvxSY3dbJhKBBX4Pm1rhWdLEFf3LxBrMtec= go.unistack.org/micro-proto/v3 v3.3.1/go.mod h1:cwRyv8uInM2I7EbU7O8Fx2Ls3N90Uw9UCCcq4olOdfE=
go.unistack.org/micro/v4 v4.0.1 h1:xo1IxbVfgh8i0eY0VeYa3cbb13u5n/Mxnp3FOgWD4Jo= go.unistack.org/micro/v3 v3.10.14 h1:7fgLpwGlCN67twhwtngJDEQvrMkUBDSA5vzZqxIDqNE=
go.unistack.org/micro/v4 v4.0.1/go.mod h1:p/J5UcSJjfHsWGT31uKoghQ5rUQZzQJBAFy+Z4+ZVMs= go.unistack.org/micro/v3 v3.10.14/go.mod h1:uMAc0U/x7dmtICCrblGf0ZLgYegu3VwQAquu+OFCw1Q=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -147,6 +150,8 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

View File

@@ -9,13 +9,13 @@ import (
"strings" "strings"
"sync" "sync"
"go.unistack.org/micro/v4/errors" "go.unistack.org/micro/v3/errors"
"go.unistack.org/micro/v4/logger" "go.unistack.org/micro/v3/logger"
"go.unistack.org/micro/v4/metadata" "go.unistack.org/micro/v3/metadata"
"go.unistack.org/micro/v4/register" "go.unistack.org/micro/v3/register"
"go.unistack.org/micro/v4/server" "go.unistack.org/micro/v3/server"
rhttp "go.unistack.org/micro/v4/util/http" rhttp "go.unistack.org/micro/v3/util/http"
rflutil "go.unistack.org/micro/v4/util/reflect" rflutil "go.unistack.org/micro/v3/util/reflect"
) )
var ( var (
@@ -60,7 +60,7 @@ func (h *httpHandler) Options() server.HandlerOptions {
return h.opts return h.opts
} }
func (h *httpServer) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, error) { func (h *Server) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, error) {
if handler == nil { if handler == nil {
return nil, fmt.Errorf("invalid handler specified: %v", handler) return nil, fmt.Errorf("invalid handler specified: %v", handler)
} }
@@ -333,7 +333,7 @@ func (h *httpServer) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, err
}, nil }, nil
} }
func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// check for http.HandlerFunc handlers // check for http.HandlerFunc handlers
if ph, _, err := h.pathHandlers.Search(r.Method, r.URL.Path); err == nil { if ph, _, err := h.pathHandlers.Search(r.Method, r.URL.Path); err == nil {
ph.(http.HandlerFunc)(w, r) ph.(http.HandlerFunc)(w, r)

View File

@@ -2,11 +2,11 @@ package handler
import ( import (
// import required packages // import required packages
_ "go.unistack.org/micro-proto/v4/openapiv3" _ "go.unistack.org/micro-proto/v3/openapiv3"
) )
//go:generate sh -c "curl -L https://github.com/swagger-api/swagger-ui/archive/refs/tags/v4.18.3.zip -o - | bsdtar -C swagger-ui --strip-components=2 -xv swagger-ui-4.18.3/dist && rm swagger-ui/*.map swagger-ui/*-es-*.js swagger-ui/swagger-ui.js swagger-ui/swagger-initializer.js" //go:generate sh -c "curl -L https://github.com/swagger-api/swagger-ui/archive/refs/tags/v4.18.3.zip -o - | bsdtar -C swagger-ui --strip-components=2 -xv swagger-ui-4.18.3/dist && rm swagger-ui/*.map swagger-ui/*-es-*.js swagger-ui/swagger-ui.js swagger-ui/swagger-initializer.js"
//go:generate sh -c "protoc -I./ -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v4) --go-micro_out='components=micro|http|server',standalone=false,debug=true,paths=source_relative:./ ./meter/meter.proto" //go:generate sh -c "protoc -I./ -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go-micro_out='components=micro|http|server',standalone=false,debug=true,paths=source_relative:./ ./meter/meter.proto"
//go:generate sh -c "protoc -I./ -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v4) --go-micro_out='components=micro|http|server',standalone=false,debug=true,paths=source_relative:./ ./health/health.proto" //go:generate sh -c "protoc -I./ -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go-micro_out='components=micro|http|server',standalone=false,debug=true,paths=source_relative:./ ./health/health.proto"

View File

@@ -1,13 +1,13 @@
package health // import "go.unistack.org/micro-server-http/v4/handler/health" package health // import "go.unistack.org/micro-server-http/v3/handler/health"
import ( import (
"context" "context"
codecpb "go.unistack.org/micro-proto/v4/codec" codecpb "go.unistack.org/micro-proto/v3/codec"
"go.unistack.org/micro/v4/errors" "go.unistack.org/micro/v3/errors"
) )
var _ HealthServiceServer = (*Handler)(nil) var _ HealthServiceServer = &Handler{}
type Handler struct { type Handler struct {
opts Options opts Options

View File

@@ -1,7 +1,7 @@
syntax = "proto3"; syntax = "proto3";
package micro.server.http.v4.handler.health; package micro.server.http.v3.handler.health;
option go_package = "go.unistack.org/micro-server-http/v4/handler/health;health"; option go_package = "go.unistack.org/micro-server-http/v3/handler/health;health";
import "api/annotations.proto"; import "api/annotations.proto";
import "openapiv3/annotations.proto"; import "openapiv3/annotations.proto";

View File

@@ -1,22 +1,22 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT. // Code generated by protoc-gen-go-micro. DO NOT EDIT.
// versions: // versions:
// - protoc-gen-go-micro v4.0.0 // - protoc-gen-go-micro v3.10.2
// - protoc v3.21.12 // - protoc v3.21.12
// source: health/health.proto // source: health.proto
package health package health
import ( import (
context "context" context "context"
codec "go.unistack.org/micro-proto/v4/codec" codec "go.unistack.org/micro-proto/v3/codec"
v4 "go.unistack.org/micro-server-http/v4" v3 "go.unistack.org/micro-server-http/v3"
) )
var ( var (
HealthServiceName = "HealthService" HealthServiceName = "HealthService"
) )
var ( var (
HealthServiceServerEndpoints = []v4.EndpointMetadata{ HealthServiceServerEndpoints = []v3.EndpointMetadata{
{ {
Name: "HealthService.Live", Name: "HealthService.Live",
Path: "/live", Path: "/live",

View File

@@ -1,14 +1,14 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT. // Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v4.0.0 // protoc-gen-go-micro version: v3.10.2
// source: health/health.proto // source: health.proto
package health package health
import ( import (
context "context" context "context"
codec "go.unistack.org/micro-proto/v4/codec" codec "go.unistack.org/micro-proto/v3/codec"
v4 "go.unistack.org/micro-server-http/v4" v3 "go.unistack.org/micro-server-http/v3"
server "go.unistack.org/micro/v4/server" server "go.unistack.org/micro/v3/server"
) )
type healthServiceServer struct { type healthServiceServer struct {
@@ -38,6 +38,6 @@ func RegisterHealthServiceServer(s server.Server, sh HealthServiceServer, opts .
} }
h := &healthServiceServer{sh} h := &healthServiceServer{sh}
var nopts []server.HandlerOption var nopts []server.HandlerOption
nopts = append(nopts, v4.HandlerEndpoints(HealthServiceServerEndpoints)) nopts = append(nopts, v3.HandlerEndpoints(HealthServiceServerEndpoints))
return s.Handle(s.NewHandler(&HealthService{h}, append(nopts, opts...)...)) return s.Handle(s.NewHandler(&HealthService{h}, append(nopts, opts...)...))
} }

View File

@@ -1,16 +1,16 @@
package meter // import "go.unistack.org/micro-server-http/v4/handler/meter" package meter // import "go.unistack.org/micro-server-http/v3/handler/meter"
import ( import (
"bytes" "bytes"
"context" "context"
codecpb "go.unistack.org/micro-proto/v4/codec" codecpb "go.unistack.org/micro-proto/v3/codec"
"go.unistack.org/micro/v4/errors" "go.unistack.org/micro/v3/errors"
"go.unistack.org/micro/v4/meter" "go.unistack.org/micro/v3/meter"
) )
// guard to fail early // guard to fail early
var _ MeterServiceServer = (*Handler)(nil) var _ MeterServiceServer = &Handler{}
type Handler struct { type Handler struct {
opts Options opts Options

View File

@@ -1,7 +1,7 @@
syntax = "proto3"; syntax = "proto3";
package micro.server.http.v4.handler.meter; package micro.server.http.v3.handler.meter;
option go_package = "go.unistack.org/micro-server-http/v4/handler/meter;meter"; option go_package = "go.unistack.org/micro-server-http/v3/handler/meter;meter";
import "api/annotations.proto"; import "api/annotations.proto";
import "openapiv3/annotations.proto"; import "openapiv3/annotations.proto";

View File

@@ -1,22 +1,22 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT. // Code generated by protoc-gen-go-micro. DO NOT EDIT.
// versions: // versions:
// - protoc-gen-go-micro v4.0.0 // - protoc-gen-go-micro v3.10.2
// - protoc v3.21.12 // - protoc v3.21.12
// source: meter/meter.proto // source: meter.proto
package meter package meter
import ( import (
context "context" context "context"
codec "go.unistack.org/micro-proto/v4/codec" codec "go.unistack.org/micro-proto/v3/codec"
v4 "go.unistack.org/micro-server-http/v4" v3 "go.unistack.org/micro-server-http/v3"
) )
var ( var (
MeterServiceName = "MeterService" MeterServiceName = "MeterService"
) )
var ( var (
MeterServiceServerEndpoints = []v4.EndpointMetadata{ MeterServiceServerEndpoints = []v3.EndpointMetadata{
{ {
Name: "MeterService.Metrics", Name: "MeterService.Metrics",
Path: "/metrics", Path: "/metrics",

View File

@@ -1,14 +1,14 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT. // Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v4.0.0 // protoc-gen-go-micro version: v3.10.2
// source: meter/meter.proto // source: meter.proto
package meter package meter
import ( import (
context "context" context "context"
codec "go.unistack.org/micro-proto/v4/codec" codec "go.unistack.org/micro-proto/v3/codec"
v4 "go.unistack.org/micro-server-http/v4" v3 "go.unistack.org/micro-server-http/v3"
server "go.unistack.org/micro/v4/server" server "go.unistack.org/micro/v3/server"
) )
type meterServiceServer struct { type meterServiceServer struct {
@@ -28,6 +28,6 @@ func RegisterMeterServiceServer(s server.Server, sh MeterServiceServer, opts ...
} }
h := &meterServiceServer{sh} h := &meterServiceServer{sh}
var nopts []server.HandlerOption var nopts []server.HandlerOption
nopts = append(nopts, v4.HandlerEndpoints(MeterServiceServerEndpoints)) nopts = append(nopts, v3.HandlerEndpoints(MeterServiceServerEndpoints))
return s.Handle(s.NewHandler(&MeterService{h}, append(nopts, opts...)...)) return s.Handle(s.NewHandler(&MeterService{h}, append(nopts, opts...)...))
} }

View File

@@ -1,4 +1,4 @@
package swaggerui // import "go.unistack.org/micro-server-http/v4/handler/swagger-ui" package swaggerui // import "go.unistack.org/micro-server-http/v3/handler/swagger-ui"
import ( import (
"embed" "embed"

48
http.go
View File

@@ -1,5 +1,5 @@
// Package http implements a go-micro.Server // Package http implements a go-micro.Server
package http // import "go.unistack.org/micro-server-http/v4" package http // import "go.unistack.org/micro-server-http/v3"
import ( import (
"context" "context"
@@ -14,18 +14,18 @@ import (
"sync" "sync"
"time" "time"
"go.unistack.org/micro/v4/broker" "go.unistack.org/micro/v3/broker"
"go.unistack.org/micro/v4/codec" "go.unistack.org/micro/v3/codec"
"go.unistack.org/micro/v4/logger" "go.unistack.org/micro/v3/logger"
"go.unistack.org/micro/v4/register" "go.unistack.org/micro/v3/register"
"go.unistack.org/micro/v4/server" "go.unistack.org/micro/v3/server"
rhttp "go.unistack.org/micro/v4/util/http" rhttp "go.unistack.org/micro/v3/util/http"
"golang.org/x/net/netutil" "golang.org/x/net/netutil"
) )
var _ server.Server = &httpServer{} var _ server.Server = (*Server)(nil)
type httpServer struct { type Server struct {
hd server.Handler hd server.Handler
rsvc *register.Service rsvc *register.Service
handlers map[string]server.Handler handlers map[string]server.Handler
@@ -40,7 +40,7 @@ type httpServer struct {
init bool init bool
} }
func (h *httpServer) newCodec(ct string) (codec.Codec, error) { func (h *Server) newCodec(ct string) (codec.Codec, error) {
if idx := strings.IndexRune(ct, ';'); idx >= 0 { if idx := strings.IndexRune(ct, ';'); idx >= 0 {
ct = ct[:idx] ct = ct[:idx]
} }
@@ -53,14 +53,14 @@ func (h *httpServer) newCodec(ct string) (codec.Codec, error) {
return nil, codec.ErrUnknownContentType return nil, codec.ErrUnknownContentType
} }
func (h *httpServer) Options() server.Options { func (h *Server) Options() server.Options {
h.Lock() h.Lock()
opts := h.opts opts := h.opts
h.Unlock() h.Unlock()
return opts return opts
} }
func (h *httpServer) Init(opts ...server.Option) error { func (h *Server) Init(opts ...server.Option) error {
if len(opts) == 0 && h.init { if len(opts) == 0 && h.init {
return nil return nil
} }
@@ -130,7 +130,7 @@ func (h *httpServer) Init(opts ...server.Option) error {
return nil return nil
} }
func (h *httpServer) Handle(handler server.Handler) error { func (h *Server) Handle(handler server.Handler) error {
// passed unknown handler // passed unknown handler
hdlr, ok := handler.(*httpHandler) hdlr, ok := handler.(*httpHandler)
if !ok { if !ok {
@@ -159,7 +159,7 @@ func (h *httpServer) Handle(handler server.Handler) error {
return nil return nil
} }
func (h *httpServer) NewHandler(handler interface{}, opts ...server.HandlerOption) server.Handler { func (h *Server) NewHandler(handler interface{}, opts ...server.HandlerOption) server.Handler {
options := server.NewHandlerOptions(opts...) options := server.NewHandlerOptions(opts...)
eps := make([]*register.Endpoint, 0, len(options.Metadata)) eps := make([]*register.Endpoint, 0, len(options.Metadata))
@@ -288,11 +288,11 @@ func (h *httpServer) NewHandler(handler interface{}, opts ...server.HandlerOptio
return hdlr return hdlr
} }
func (h *httpServer) NewSubscriber(topic string, handler interface{}, opts ...server.SubscriberOption) server.Subscriber { func (h *Server) NewSubscriber(topic string, handler interface{}, opts ...server.SubscriberOption) server.Subscriber {
return newSubscriber(topic, handler, opts...) return newSubscriber(topic, handler, opts...)
} }
func (h *httpServer) Subscribe(sb server.Subscriber) error { func (h *Server) Subscribe(sb server.Subscriber) error {
sub, ok := sb.(*httpSubscriber) sub, ok := sb.(*httpSubscriber)
if !ok { if !ok {
return fmt.Errorf("invalid subscriber: expected *httpSubscriber") return fmt.Errorf("invalid subscriber: expected *httpSubscriber")
@@ -317,7 +317,7 @@ func (h *httpServer) Subscribe(sb server.Subscriber) error {
return nil return nil
} }
func (h *httpServer) Register() error { func (h *Server) Register() error {
var eps []*register.Endpoint var eps []*register.Endpoint
h.RLock() h.RLock()
for _, hdlr := range h.handlers { for _, hdlr := range h.handlers {
@@ -408,7 +408,7 @@ func (h *httpServer) Register() error {
return nil return nil
} }
func (h *httpServer) Deregister() error { func (h *Server) Deregister() error {
h.RLock() h.RLock()
config := h.opts config := h.opts
h.RUnlock() h.RUnlock()
@@ -456,7 +456,7 @@ func (h *httpServer) Deregister() error {
return nil return nil
} }
func (h *httpServer) Start() error { func (h *Server) Start() error {
h.RLock() h.RLock()
config := h.opts config := h.opts
h.RUnlock() h.RUnlock()
@@ -636,27 +636,27 @@ func (h *httpServer) Start() error {
return nil return nil
} }
func (h *httpServer) Stop() error { func (h *Server) Stop() error {
ch := make(chan error) ch := make(chan error)
h.exit <- ch h.exit <- ch
return <-ch return <-ch
} }
func (h *httpServer) String() string { func (h *Server) String() string {
return "http" return "http"
} }
func (h *httpServer) Name() string { func (h *Server) Name() string {
return h.opts.Name return h.opts.Name
} }
func NewServer(opts ...server.Option) *httpServer { func NewServer(opts ...server.Option) *Server {
options := server.NewOptions(opts...) options := server.NewOptions(opts...)
eh := DefaultErrorHandler eh := DefaultErrorHandler
if v, ok := options.Context.Value(errorHandlerKey{}).(errorHandler); ok && v != nil { if v, ok := options.Context.Value(errorHandlerKey{}).(errorHandler); ok && v != nil {
eh = v eh = v
} }
return &httpServer{ return &Server{
opts: options, opts: options,
exit: make(chan chan error), exit: make(chan chan error),
subscribers: make(map[*httpSubscriber][]broker.Subscriber), subscribers: make(map[*httpSubscriber][]broker.Subscriber),

View File

@@ -1,8 +1,8 @@
package http package http
import ( import (
"go.unistack.org/micro/v4/codec" "go.unistack.org/micro/v3/codec"
"go.unistack.org/micro/v4/metadata" "go.unistack.org/micro/v3/metadata"
) )
type httpMessage struct { type httpMessage struct {

View File

@@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"go.unistack.org/micro/v4/server" "go.unistack.org/micro/v3/server"
) )
// SetError pass error to caller // SetError pass error to caller
@@ -85,8 +85,8 @@ func Middleware(mw ...func(http.Handler) http.Handler) server.Option {
type serverKey struct{} type serverKey struct{}
// Server provide ability to pass *http.Server // HTTPServer provide ability to pass *http.Server
func Server(hs *http.Server) server.Option { func HTTPServer(hs *http.Server) server.Option {
return server.SetOption(serverKey{}, hs) return server.SetOption(serverKey{}, hs)
} }

View File

@@ -3,9 +3,9 @@ package http
import ( import (
"io" "io"
"go.unistack.org/micro/v4/codec" "go.unistack.org/micro/v3/codec"
"go.unistack.org/micro/v4/metadata" "go.unistack.org/micro/v3/metadata"
"go.unistack.org/micro/v4/server" "go.unistack.org/micro/v3/server"
) )
var ( var (

View File

@@ -7,7 +7,7 @@ import (
"unicode" "unicode"
"unicode/utf8" "unicode/utf8"
"go.unistack.org/micro/v4/server" "go.unistack.org/micro/v3/server"
) )
type methodType struct { type methodType struct {

View File

@@ -7,11 +7,11 @@ import (
"reflect" "reflect"
"strings" "strings"
"go.unistack.org/micro/v4/broker" "go.unistack.org/micro/v3/broker"
"go.unistack.org/micro/v4/codec" "go.unistack.org/micro/v3/codec"
"go.unistack.org/micro/v4/metadata" "go.unistack.org/micro/v3/metadata"
"go.unistack.org/micro/v4/register" "go.unistack.org/micro/v3/register"
"go.unistack.org/micro/v4/server" "go.unistack.org/micro/v3/server"
) )
var typeOfError = reflect.TypeOf((*error)(nil)).Elem() var typeOfError = reflect.TypeOf((*error)(nil)).Elem()
@@ -101,7 +101,7 @@ func newSubscriber(topic string, sub interface{}, opts ...server.SubscriberOptio
} }
} }
func (s *httpServer) createSubHandler(sb *httpSubscriber, opts server.Options) broker.Handler { func (s *Server) createSubHandler(sb *httpSubscriber, opts server.Options) broker.Handler {
return func(p broker.Event) error { return func(p broker.Event) error {
msg := p.Message() msg := p.Message()
ct := msg.Header["Content-Type"] ct := msg.Header["Content-Type"]

View File

@@ -5,8 +5,8 @@ import (
"net/http" "net/http"
"strings" "strings"
"go.unistack.org/micro/v4/metadata" "go.unistack.org/micro/v3/metadata"
rutil "go.unistack.org/micro/v4/util/reflect" rutil "go.unistack.org/micro/v3/util/reflect"
) )
func FillRequest(ctx context.Context, req interface{}, opts ...FillRequestOption) error { func FillRequest(ctx context.Context, req interface{}, opts ...FillRequestOption) error {

View File

@@ -7,7 +7,7 @@ import (
"strings" "strings"
"testing" "testing"
"go.unistack.org/micro/v4/metadata" "go.unistack.org/micro/v3/metadata"
) )
func TestFillrequest(t *testing.T) { func TestFillrequest(t *testing.T) {