Module mechanism

Service center(SC) support an extend modules mechanism that developers can new some features in SC easily.

Just 4 steps, you can add a module in service center

  1. Create a module(package) under the github.com/apache/servicecomb-service-center/server/resource package.
  2. Here you just need to implement the controller and service interfaces in your module.
  3. And register service to SC when the module initializes.
  4. Import the package in github.com/apache/servicecomb-service-center/server/bootstrap/bootstrap.go

Quit start for the RESTful module

Implement the RouteGroup interface.

package hello

import (
	"net/http"
    
	"github.com/apache/servicecomb-service-center/pkg/rest"
)

type HelloService struct {
}

func (s *HelloService) URLPatterns() []rest.Route {
	return []rest.Route{
		{
		    rest.HTTP_METHOD_GET, // Method is one of the following: GET,PUT,POST,DELETE
		    "/helloWorld", // Path contains a path pattern
		    s.SayHello, // rest callback function for the specified Method and Path
        },
	}
}

func (s *HelloService) SayHello(w http.ResponseWriter, r *http.Request) {
    // say Hi
}

Register the service in SC ROA framework when the module initializes.

package hello

import "github.com/apache/servicecomb-service-center/pkg/rest"

func init() {
    rest.RegisterServant(&HelloService{})
}

Modify bootstarp.go file to import your module.

// module
import _ "github.com/apache/servicecomb-service-center/server/resource/hello"