clienthandlers

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2020 License: MIT Imports: 10 Imported by: 0

README

Go Report Card License Version Built with GoLang

GoBlender client

Sample project for client specific code for GoBlender.

Setup

First, install goblender.

All client specific code lives in ./client/clienthandlers, and is its own git repository. When working in JetBrains Goland, you must create (or clone) a git repository in this location, and then add the directory in Preferences -> Version Control.

Updating on server

Change update.sh in GoBlender root folder so as to enable git pull of client:

# uncomment if using custom client code
#cd ./client/clienthandlers
#git pull
#cd ../..

# run migrations for pg
# soda migrate -c ../../migrations-pg/database.yml

#run client migrations for mariadb
# soda migrate -c ../../database.yml

After changing, it should look like this (assuming you want to run postgres migrations):

# uncomment if using custom client code
cd ./client/clienthandlers
git pull
cd ../..

# run migrations for pg
soda migrate -c ../../migrations-pg/database.yml

#run client migrations for mariadb
# soda migrate -c ../../database.yml

Using custom templates

Inside of clientviews there are two folders: public and private. If you wish to use the base templates from goBlender to create templates, do it like this:

For public pages:

{{template "base" .}}

{{define "title"}}Some title{{end}}

{{define "body"}}
    <p>Put whatever you want here</p>
{{end}}

For admin pages:

{{template "admin-base" .}}

{{define "title"}}Some Title - vMaintain Admin{{end}}

{{define "admin-title"}}Some title{{end}}
{{define "content-title"}}Some title{{end}}

{{define "content"}}
    <p>Some content</p>
{{end}}

Note

You can override anything in the base templates, or specific pages/partials, but putting a file in client/clientviews/public, client/clientviews/public/partials, client/clientviews/admin, or client/clientviews/admin/partials.

Client Specific Migrations

Migrations live in client/migrations. To run them, add the -c flag to soda, e.g.:

To generate Postgres migrations:

cd client/clienthandlers
soda -c ../../migrations-pg/database.yml generate fizz SomeMigrationName

To run Postgres migrations:

cd client/clienthandlers
soda -c ../../migrations-pg/database.yml migrate

To generate MariaDB/MySQL migrations:

cd client/clienthandlers
soda -c ../../database.yml generate fizz SomeMigration

To run MariaDB/MySQL migrations:

cd client/clienthandlers
soda -c ../../database.yml migrate

Middleware

Add custom middleware to ./client/clienthandlers/client-middleware.go, e.g.:

// SomeMiddleware is sample middleware
func SomeMiddleware(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        ok := true
        // perform some logic to set ok
        
        if ok {
            next.ServeHTTP(w, r)
        } else {
         helpers.ClientError(w, http.StatusUnauthorized)
        }
    })
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientInit

func ClientInit(conf config.AppConfig, parentDriver *driver.DB, rep *handlers.DBRepo)

ClientInit gives client code access to goBlender configuration

func ClientRoutes

func ClientRoutes(mux *pat.PatternServeMux, standardMiddleWare, dynamicMiddleware alice.Chain) (*pat.PatternServeMux, error)

ClientRoutes is used to handle custom routes for specific clients. Prepend some unique (and site wide) value to the start of each route in order to avoid clashes with pages, etc. Middleware can be applied by importing and using the middleware.* functions.

func CustomShowHome added in v1.1.0

func CustomShowHome(w http.ResponseWriter, r *http.Request)

CustomShowHome is a sample handler which returns the home page using our local page template for the client, and is called from client-routes.go using a route that overrides the one in goBlender. This allows us to build custom functionality without having to use non-standard routes.

func NewClientMiddleware added in v1.0.3

func NewClientMiddleware(app config.AppConfig)

NewClientMiddleware sets app config for middleware

func SomeHandler

func SomeHandler(w http.ResponseWriter, r *http.Request)

SomeHandler is an example handler

func SomeRole added in v1.0.3

func SomeRole(next http.Handler) http.Handler

SomeRole is a sample role

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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