services

package
v0.0.0-...-08e7634 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2020 License: Apache-2.0 Imports: 1 Imported by: 0

README

Creating a New Service

  1. Create a directory/package that will contain your service (e.g. /internal/services/subscriptions)
  2. Make a README.md file (e.g. /internal/services/subscriptions/README.md) that gives an overview of your service along with a sample JSON response
  3. Create a models.go file in your new service package (e.g. /internal/services/subscriptions/models.go) and add in a constructor function that returns a struct that represents your service's JSON response populated with sane defaults
  4. Create a handlers.go file and implement whatever handler functions you need (return JSON using the models you created constructors for)
    • We use Echo for our HTTP routing so you'll need to make your handler functions match a structure similar to the one below:
    func hello(c echo.Context) error {
    return c.String(http.StatusOK, "Hello, World!")
    }
    
  5. Make a service.go file in your new directory (e.g. /internal/services/subscriptions/service.go), implement GetHandlers() as defined in /internal/services/interface.go, and add your new handler functions (defined in handlers.go that you created in a step above) to the map that's returned
  6. Open cerulean.go in the root of the repository and add your new service to the svcs slice inside the New() function
    • This allows Echo to find and map our endpoints to HTTP listeners
  7. To finish things off, be a good person and create a handlers_test.go file and write a couple unit tests

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// Verb is a string containing an HTTP verb value (https://golang.org/src/net/http/method.go)
	Verb string
	Func echo.HandlerFunc
}

Handler is a helper struct that allows us to iterate over handlers to pass to Echo

type Service

type Service interface {
	// GetHandlers returns a map of key/value pairs where the key is the HTTP route and the value is a Handler struct (an Echo handler function along with its HTTP verb)
	GetHandlers() map[string]Handler
}

Service aims to help autodiscover our available services

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL