harness

package
v0.0.0-...-5e61291 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2019 License: GPL-2.0, GPL-2.0-or-later Imports: 29 Imported by: 0

Documentation

Overview

Package harness for a Revel Framework.

It has a following responsibilities:

  1. Parse the user program, generating a main.go file that registers controller classes and starts the user's server.
  2. Build and run the user program. Show compile errors.
  3. Monitor the user source and re-build / restart the program when necessary.

Source files are generated in the app/tmp directory.

Index

Constants

View Source
const RevelMainTemplate = `` /* 1661-byte string literal not displayed */

RevelMainTemplate template for app/tmp/main.go

View Source
const RevelRoutesTemplate = `` /* 557-byte string literal not displayed */

RevelRoutesTemplate template for app/conf/routes

Variables

This section is empty.

Functions

func IsBuiltinType

func IsBuiltinType(name string) bool

IsBuiltinType checks the given type is built-in types of Go

Types

type App

type App struct {
	BinaryPath string // Path to the app executable
	Port       int    // Port to pass as a command line argument.
	// contains filtered or unexported fields
}

App contains the configuration for running a Revel app. (Not for the app itself) Its only purpose is constructing the command to execute.

func Build

func Build(buildFlags ...string) (app *App, compileError *revel.Error)

Build the app: 1. Generate the the main.go file. 2. Run the appropriate "go build" command. Requires that revel.Init has been called previously. Returns the path to the built binary, and an error if there was a problem building it.

func NewApp

func NewApp(binPath string) *App

NewApp returns app instance with binary path in it

func (*App) Cmd

func (a *App) Cmd() AppCmd

Cmd returns a command to run the app server using the current configuration.

func (*App) Kill

func (a *App) Kill()

Kill the last app command returned.

type AppCmd

type AppCmd struct {
	*exec.Cmd
}

AppCmd manages the running of a Revel app server. It requires revel.Init to have been called previously.

func NewAppCmd

func NewAppCmd(binPath string, port int) AppCmd

NewAppCmd returns the AppCmd with parameters initialized for running app

func (AppCmd) Kill

func (cmd AppCmd) Kill()

Kill terminates the app server if it's running.

func (AppCmd) Run

func (cmd AppCmd) Run()

Run the app server inline. Never returns.

func (AppCmd) Start

func (cmd AppCmd) Start() error

Start the app server, and wait until it is ready to serve requests.

type Harness

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

Harness reverse proxies requests to the application server. It builds / runs / rebuilds / restarts the server when code is changed.

func NewHarness

func NewHarness() *Harness

NewHarness method returns a reverse proxy that forwards requests to the given port.

func (*Harness) Refresh

func (h *Harness) Refresh() (err *revel.Error)

Refresh method rebuilds the Revel application and run it on the given port.

func (*Harness) Run

func (h *Harness) Run()

Run the harness, which listens for requests and proxies them to the app server, which it runs and rebuilds as necessary.

func (*Harness) ServeHTTP

func (h *Harness) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles all requests. It checks for changes to app, rebuilds if necessary, and forwards the request.

func (*Harness) WatchDir

func (h *Harness) WatchDir(info os.FileInfo) bool

WatchDir method returns false to file matches with doNotWatch otheriwse true

func (*Harness) WatchFile

func (h *Harness) WatchFile(filename string) bool

WatchFile method returns true given filename HasSuffix of ".go" otheriwse false - implements revel.DiscerningListener

type MethodArg

type MethodArg struct {
	Name       string   // Name of the argument.
	TypeExpr   TypeExpr // The name of the type, e.g. "int", "*pkg.UserType"
	ImportPath string   // If the arg is of an imported type, this is the import path.
}

MethodArg holds the information of one argument

type MethodSpec

type MethodSpec struct {
	Name        string        // Name of the method, e.g. "Index"
	Args        []*MethodArg  // Argument descriptors
	RenderCalls []*methodCall // Descriptions of Render() invocations from this Method.
}

MethodSpec holds the information of one Method

type SourceInfo

type SourceInfo struct {
	// StructSpecs lists type info for all structs found under the code paths.
	// They may be queried to determine which ones (transitively) embed certain types.
	StructSpecs []*TypeInfo
	// ValidationKeys provides a two-level lookup.  The keys are:
	// 1. The fully-qualified function name,
	//    e.g. "github.com/revel/examples/chat/app/controllers.(*Application).Action"
	// 2. Within that func's file, the line number of the (overall) expression statement.
	//    e.g. the line returned from runtime.Caller()
	// The result of the lookup the name of variable being validated.
	ValidationKeys map[string]map[int]string
	// A list of import paths.
	// Revel notices files with an init() function and imports that package.
	InitImportPaths []string
	// contains filtered or unexported fields
}

SourceInfo is the top-level struct containing all extracted information about the app source code, used to generate main.go.

func ProcessSource

func ProcessSource(roots []string) (*SourceInfo, *revel.Error)

ProcessSource parses the app controllers directory and returns a list of the controller types found. Otherwise CompileError if the parsing fails.

func (*SourceInfo) ControllerSpecs

func (s *SourceInfo) ControllerSpecs() []*TypeInfo

ControllerSpecs returns the all the contollers that embeds `revel.Controller`

func (*SourceInfo) TestSuites

func (s *SourceInfo) TestSuites() []*TypeInfo

TestSuites returns the all the Application tests that embeds `testing.TestSuite`

func (*SourceInfo) TypesThatEmbed

func (s *SourceInfo) TypesThatEmbed(targetType, packageFilter string) (filtered []*TypeInfo)

TypesThatEmbed returns all types that (directly or indirectly) embed the target type, which must be a fully qualified type name, e.g. "github.com/revel/revel.Controller"

type TypeExpr

type TypeExpr struct {
	Expr    string // The unqualified type expression, e.g. "[]*MyType"
	PkgName string // The default package idenifier

	Valid bool
	// contains filtered or unexported fields
}

TypeExpr provides a type name that may be rewritten to use a package name.

func NewTypeExpr

func NewTypeExpr(pkgName string, expr ast.Expr) TypeExpr

NewTypeExpr returns the syntactic expression for referencing this type in Go.

func (TypeExpr) TypeName

func (e TypeExpr) TypeName(pkgOverride string) string

TypeName returns the fully-qualified type name for this expression. The caller may optionally specify a package name to override the default.

type TypeInfo

type TypeInfo struct {
	StructName  string // e.g. "Application"
	ImportPath  string // e.g. "github.com/revel/examples/chat/app/controllers"
	PackageName string // e.g. "controllers"
	MethodSpecs []*MethodSpec
	// contains filtered or unexported fields
}

TypeInfo summarizes information about a struct type in the app source code.

func (*TypeInfo) String

func (s *TypeInfo) String() string

Jump to

Keyboard shortcuts

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