handlers

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package handlers renders the Go source files found in <svcname>/handlers/. Most importantly, it handles rendering and modifying the <svcname>/handlers/handlers.go file, while making sure that existing code in that handlers.go file is not deleted.

Index

Constants

View Source
const HookPath = "handlers/hooks.gotemplate"
View Source
const MiddlewaresPath = "handlers/middlewares.gotemplate"

MiddlewaresPath is the path to the middleware gotemplate file.

View Source
const ServerHandlerPath = "handlers/handlers.gotemplate"

ServerHadlerPath is the relative path to the server handler template file

Variables

This section is empty.

Functions

func New

func New(svc *svcdef.Service, prev io.Reader) (gengokit.Renderable, error)

New returns a truss.Renderable capable of updating server handlers. New should be passed the previous version of the server handler to parse.

func NewHook

func NewHook(prev io.Reader) gengokit.Renderable

NewHook returns a new HookRender

Types

type HookRender

type HookRender struct {
	// contains filtered or unexported fields
}

func (*HookRender) Render

func (h *HookRender) Render(_ string, data *gengokit.Data) (io.Reader, error)

Render returns an io.Reader with the contents of <svcname>/handlers/hooks.go. If hooks.go does not already exist, then it's rendered anew from the templates defined in 'gengokit/handlers/templates/hook.go'. If hooks.go does exist already, then:

  1. Modify the new code so that it will import "{{.ImportPath}}/svc/server" if it doesn't already.
  2. Add the InterruptHandler if it doesn't exist already
  3. Add the SetConfig function if it doesn't exist already

type Middlewares

type Middlewares struct {
	// contains filtered or unexported fields
}

Middlewares satisfies the gengokit.Renderable interface to render middlewares.

func NewMiddlewares

func NewMiddlewares() *Middlewares

NewMiddlewares returns a Renderable that renders the middlewares.go file.

func (*Middlewares) Load

func (m *Middlewares) Load(prev io.Reader)

Load loads the previous version of the middleware file.

func (*Middlewares) Render

func (m *Middlewares) Render(path string, data *gengokit.Data) (io.Reader, error)

Render creates the middlewares.go file. With no previous version it renders the templates, if there was a previous version loaded in, it passes that through.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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