app

package
v0.0.0-...-772259c Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

README

GhastApp

The Ghast framework ships encapsulated in the GhastApp struct. However, you can use individual pieces of Ghast if you would prefer. I've tried to make all of these pieces provide some value individually, but the router is the only real candidate for use outside of the framework at the moment. That being said, GhastApp takes care of setting up your application, dependency injection container, and router. If you're building a full-fledged application, I strongly recommend using the GhastApp as it is the intended way to use Ghast.

TLDR: If you're not sure if you want the GhastApp or GhastRouter, use the GhastApp unless you are specifically only wanting routing.

Using ghast new MyProjectName from the command line will generate a new main.go file for you that's setup to use GhastApp.

package main

import (
	"fmt"
	"net/http"

	ghastApp "github.com/bradcypert/ghast/pkg/app"
	ghastRouter "github.com/bradcypert/ghast/pkg/router"
)

func main() {
	router := ghastRouter.Router{}

	// Want to use controllers instead? Try running "ghast make controller MyController" from your terminal
	router.Get("/", func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusOK)
		fmt.Fprint(w, "Hello from Ghast!")
	})

	app := ghastApp.NewApp()
	app.SetRouter(router)
	app.Start()
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AppContext context.Context

AppContext to be used by Globally required application objects. Warning: this context is essential to Ghast's ability to function correctly. Override values in this context at your own risk.

Functions

This section is empty.

Types

type App

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

App defines a struct that encapsulates the entire ghast framework + application specific settings generally, you should use the NewApp function instead of creating a struct instance directly, but we have chosen to support creating the struct directly to have better control of the app creation process.

func GetApp

func GetApp(c *ghastContainer.Container) App

GetApp gets the app instance out of a given container

func NewApp

func NewApp() App

NewApp constructor function for ghast app Generally, you'll want to use this over creating a new struct instance directly.

func NewAppWithConfig

func NewAppWithConfig(debugOptions DebugOptions) App

NewAppWithConfig constructor function for ghast app with a separate app config (used for debugging purposes) Note: depending on your config, this can log a LOT of data to STDOUT. You will most likely want `NewApp` for production deployments.

func (App) GetViewSet

func (a App) GetViewSet() *jet.Set

GetViewSet Gets the Application's JET view set

func (App) Register

func (a App) Register(key string, fn func(c *ghastContainer.Container) interface{})

Register registers a new key value binding in the Application's DI container

func (App) SetRouter

func (a App) SetRouter(router ghastRouter.Router)

SetRouter sets a user configured ghast router to be used as the application's default router.

func (App) SetServerConfig

func (a App) SetServerConfig(config *http.Server)

SetServerConfig provides the app with a custom use Server configuration

func (App) Start

func (a App) Start()

Start boots up the HTTP server and binds a route listener

type DebugOptions

type DebugOptions struct {
	ShouldDebugConfig bool
}

DebugOptions provides additional options for debugging application creation and start

Jump to

Keyboard shortcuts

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