Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web service handler with []*api.Endpoint option #1097

Closed
hb-chen opened this issue Jan 9, 2020 · 4 comments
Closed

web service handler with []*api.Endpoint option #1097

hb-chen opened this issue Jan 9, 2020 · 4 comments

Comments

@hb-chen
Copy link
Contributor

hb-chen commented Jan 9, 2020

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
Some times we may use one micro api gateway for rpc and http at the same time.
Can we add a endpoints ...*api.Endpoint option for go-micro/web/Service interface Handle() and HandleFunc() func.
My implement

So that user can use web/Service start a http service for micro api gateway. Otherwise users need to implement it themselves.
Just an idea to see if it's necessary to add to the go-micro/web

e.g.

package main

import (
	"fmt"
	"net/http"

	"github.com/hb-go/micro-plugins/web"
	"github.com/micro/go-micro/api"
	"github.com/micro/go-micro/util/log"
)

func main() {
	// create new web service
	service := web.NewService(
		web.Name("go.micro.api.console.web"),
		web.Version("latest"),
	)

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

	service.Handle("/console/", &handler{}, &api.Endpoint{
		Name:    "console",
		Host:    []string{"localhost:8080"},
		Path:    []string{"^/console"},
		Method:  []string{"POST", "GET", "DELETE"},
		Handler: "proxy",
	})

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

type handler struct {
}

func (*handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte(fmt.Sprintf("request success, path: %v", r.URL.Path)))
}

Additional context
Add any other context or screenshots about the feature request here.

@vtolstov
Copy link
Contributor

@asim what you think? imho it may be useful

@crazybber
Copy link
Contributor

deserve to be discussed.

@vtolstov
Copy link
Contributor

this is already covered by handler rpc, does we need also proxy handler support for this?

@asim
Copy link
Member

asim commented May 19, 2020

web service != api service

we're working on a model of consolidation, we just don't have an answer yet

@asim asim closed this as completed May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants