thruster

package module
v0.0.0-...-2bfe9c5 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2015 License: MIT Imports: 7 Imported by: 0

README

thruster Build Status

Simple wrapper around gin.Engine, that reads configuration from a config file.

Basic Usage

  config := thruster.Config{
    Hostname: "localhost",
    Port:     3000,
  }
  server := thruster.NewServer(config)

  handler := func(c *gin.Context) {
    ...
  }
  server.AddHandler(thruster.GET, "my_handler", handler)
  server.Start()

  # GET http://localhost/my_handler

JSON

  ...
  server := thruster.NewServer(config)

  handler := func(c *gin.Context) (interface{}, error) {
    return map[string]string{"my":"response"}, nil
  }
  server.AddJSONHandler(thruster.GET, "my_handler", handler)
  server.Start()

  # GET http://localhost/my_handler
  # => {"my":"response"}

HTTP Auth

  config := thruster.Config{
    Hostname: "localhost",
    Port:     3000,
    HTTPAuth: []thruster.HTTPAuth{
      thurster.NewHTTPAuth("user1", "passwd1"),
      thurster.NewHTTPAuth("user2", "passwd2"),
      ...
    },
  }
  server := thruster.NewServer(config)

  # GET http://user1:passwd1@localhost/
  # GET http://user2:passwd2@localhost/

TLS

Option1 - certificate in a file
  config := thruster.Config{
    Hostname:    "localhost",
    Port:        3000,
    TLS:         true,
    Certificate: "/path/to/certificate",
    PublicKey:   "/path/to/public/key",
  }
  server := thruster.NewServer(config)

  # GET https://localhost/
Option2 - inline certificate
  config := thruster.Config{
    Hostname:    "localhost",
    Port:        3000,
    TLS:         true,
    Certificate: "-----BEGIN CERTIFICATE----- .... ",
    PublicKey:   "-----BEGIN RSA PRIVATE KEY----- ....",
  }
  server := thruster.NewServer(config)

  # GET https://localhost/

RESTful Resource

  ...
  server.AddResource("users", controller)

  # GET /users -> controller.Index
  # GET /users/1 -> controller.Show
  # POST /users -> controller.Create
  # PUT /users/1 -> controller.Update
  # DELETE /users/1 -> controller.Destroy
  ...
  server.AddJSONResource("users", jsonController)

  # GET /users -> jsonController.Index
  # GET /users/1 -> jsonController.Show
  # POST /users -> jsonController.Create
  # PUT /users/1 -> jsonController.Update
  # DELETE /users/1 -> jsonController.Destroy

Reading configuration from YAML

  config, err := thruster.NewConfig("/path/to/config.yml")
Sample Config.yaml
  hostname: localhost
  port: 8888
  http_auth:
  - username: admin
    password: 12345
  - username: user1
    password: 6666
  tls: true
  certificate: /etc/certificate1
  public_key: /etc/public_key

Documentation

Index

Constants

View Source
const (
	GET    string = "GET"
	POST   string = "POST"
	PUT    string = "PUT"
	DELETE string = "DELETE"
)

Variables

View Source
var (
	ErrNotFound error = errors.New("Not Found")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Hostname string     `yaml:"hostname"`
	Port     int        `yaml:"port"`
	HTTPAuth []HTTPAuth `yaml:"http_auth"`
	TLS      bool       `yaml:"tls"`

	Certificate string `yaml:"certificate"`
	PublicKey   string `yaml:"public_key"`
}

func NewConfig

func NewConfig(path string) (Config, error)

type Controller

type Controller interface {
	Index(context *gin.Context)
	Show(context *gin.Context)
	Create(context *gin.Context)
	Update(context *gin.Context)
	Destroy(context *gin.Context)
}

type HTTPAuth

type HTTPAuth struct {
	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

func NewHTTPAuth

func NewHTTPAuth(username, password string) HTTPAuth

type JSONController

type JSONController interface {
	Index(context *gin.Context) (interface{}, error)
	Show(context *gin.Context) (interface{}, error)
	Create(context *gin.Context) (interface{}, error)
	Update(context *gin.Context) (interface{}, error)
	Destroy(context *gin.Context) (interface{}, error)
}

type JSONHandler

type JSONHandler func(*gin.Context) (interface{}, error)

type Server

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

func NewServer

func NewServer(config Config) *Server

func NewServerWithEngine

func NewServerWithEngine(config Config, engine *gin.Engine) *Server

func (*Server) AddHandler

func (s *Server) AddHandler(method, path string, handler gin.HandlerFunc)

func (*Server) AddJSONHandler

func (s *Server) AddJSONHandler(method, path string, handler JSONHandler)

func (*Server) AddJSONResource

func (s *Server) AddJSONResource(path string, controller JSONController)

func (*Server) AddResource

func (s *Server) AddResource(path string, controller Controller)

func (*Server) Run

func (s *Server) Run() error

Directories

Path Synopsis
Godeps
_workspace/src/github.com/onsi/ginkgo
Ginkgo is a BDD-style testing framework for Golang The godoc documentation describes Ginkgo's API.
Ginkgo is a BDD-style testing framework for Golang The godoc documentation describes Ginkgo's API.
_workspace/src/github.com/onsi/ginkgo/config
Ginkgo accepts a number of configuration options.
Ginkgo accepts a number of configuration options.
_workspace/src/github.com/onsi/ginkgo/ginkgo
The Ginkgo CLI The Ginkgo CLI is fully documented [here](http://onsi.github.io/ginkgo/#the_ginkgo_cli) You can also learn more by running: ginkgo help Here are some of the more commonly used commands: To install: go install github.com/onsi/ginkgo/ginkgo To run tests: ginkgo To run tests in all subdirectories: ginkgo -r To run tests in particular packages: ginkgo <flags> /path/to/package /path/to/another/package To pass arguments/flags to your tests: ginkgo <flags> <packages> -- <pass-throughs> To run tests in parallel ginkgo -p this will automatically detect the optimal number of nodes to use.
The Ginkgo CLI The Ginkgo CLI is fully documented [here](http://onsi.github.io/ginkgo/#the_ginkgo_cli) You can also learn more by running: ginkgo help Here are some of the more commonly used commands: To install: go install github.com/onsi/ginkgo/ginkgo To run tests: ginkgo To run tests in all subdirectories: ginkgo -r To run tests in particular packages: ginkgo <flags> /path/to/package /path/to/another/package To pass arguments/flags to your tests: ginkgo <flags> <packages> -- <pass-throughs> To run tests in parallel ginkgo -p this will automatically detect the optimal number of nodes to use.
_workspace/src/github.com/onsi/ginkgo/internal/remote
Aggregator is a reporter used by the Ginkgo CLI to aggregate and present parallel test output coherently as tests complete.
Aggregator is a reporter used by the Ginkgo CLI to aggregate and present parallel test output coherently as tests complete.
_workspace/src/github.com/onsi/ginkgo/reporters
Ginkgo's Default Reporter A number of command line flags are available to tweak Ginkgo's default output.
Ginkgo's Default Reporter A number of command line flags are available to tweak Ginkgo's default output.
_workspace/src/github.com/onsi/gomega
Gomega is the Ginkgo BDD-style testing framework's preferred matcher library.
Gomega is the Ginkgo BDD-style testing framework's preferred matcher library.
_workspace/src/github.com/onsi/gomega/format
Gomega's format package pretty-prints objects.
Gomega's format package pretty-prints objects.
_workspace/src/github.com/onsi/gomega/gbytes
Package gbytes provides a buffer that supports incrementally detecting input.
Package gbytes provides a buffer that supports incrementally detecting input.
_workspace/src/github.com/onsi/gomega/gexec
Package gexec provides support for testing external processes.
Package gexec provides support for testing external processes.
_workspace/src/github.com/onsi/gomega/ghttp
Package ghttp supports testing HTTP clients by providing a test server (simply a thin wrapper around httptest's server) that supports registering multiple handlers.
Package ghttp supports testing HTTP clients by providing a test server (simply a thin wrapper around httptest's server) that supports registering multiple handlers.
_workspace/src/github.com/onsi/gomega/matchers
Gomega matchers This package implements the Gomega matchers and does not typically need to be imported.
Gomega matchers This package implements the Gomega matchers and does not typically need to be imported.
_workspace/src/golang.org/x/net/context
Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes.
Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes.
_workspace/src/gopkg.in/bluesuncorp/validator.v5
Package validator implements value validations for structs and individual fields based on tags.
Package validator implements value validations for structs and individual fields based on tags.
_workspace/src/gopkg.in/yaml.v2
Package yaml implements YAML support for the Go language.
Package yaml implements YAML support for the Go language.
This file was generated by counterfeiter This file was generated by counterfeiter
This file was generated by counterfeiter This file was generated by counterfeiter

Jump to

Keyboard shortcuts

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