gottp

package module
v0.0.0-...-4ad85d2 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2014 License: Apache-2.0 Imports: 16 Imported by: 0

README

Build Status

gottp

Gottp is not a regular front-end server to do customer facing websites. It has been designed using backend servers in mind. It offers a variety of features like Call Aggregation using Asynchronous or Blocking Pipes very much like Batch requests in Graph API. https://developers.facebook.com/docs/graph-api/making-multiple-requests

Installation

go get github.com/Simversity/gottp

Getting Started

A sample application named helloWorld is available inside the tests directory of your checkout

To start building a web service using gottp just create a new project with the following structure.

  • conf.go -> Configuration
  • main.go -> main Server engine
  • urls.go -> Register acceptable urls & handlers.
  • handlers/hello.go -> Register handlers that process the request.

conf.go

A minimalist configuration looks like:

package main

import "github.com/Simversity/gottp"

type config struct {
	Gottp gottp.SettingsMap
}

func (self *config) MakeConfig(configPath string) {
	gottp.Settings = self.Gottp
}

var settings config

main.go

A sample main.go would look like:

package main

import (
    "log"
	"github.com/Simversity/gottp"
)

func sysInit() {
	<-(gottp.SysInitChan) //Buffered Channel to receive the server upstart boolean
	log.Println("System is ready to Serve")
}

func main() {
	go sysInit()
	gottp.BindHandlers(urls) //Urls is a slice of all the registered urls.
	gottp.MakeServer(&settings)
}

urls.go

Urls are of type gottp.Url

type Url struct {
	name    string //shortname of the url
	url     string //provided regular pattern
	handler func(r *Request) //ReuqestHandler 
	pattern *regexp.Regexp //Compiled Regular Expression
}

A sample urls.go looks like:

package main

import (
	"github.com/Simversity/gottp"
)

var urls = []*gottp.Url{
    gottp.NewUrl("hello", "/hello/\\w{3,5}/?$", handlers.HelloMessage),
}

This would match all urls that are like "/hello/world" or "/hello/greet"

handlers.go

A sample handler looks like:

package handlers

import (
	"github.com/Simversity/gottp"
)

func HelloMessage(req *gottp.Request) {
    req.Write("hello world")
}

Build & Run

go install test && test

Point your browser to http://127.0.0.1:8005/hello/check

Should give you a JSON output:

{
    "data": "hello world",
    "message": "",
    "status": 200
}

Available URLs

You can visit http://127.0.0.1:8005/urls to access the URLs exposed by your application.

Sample Output:

{
    "data": {
        "hello": "/hello/\\w{3,5}/?$"
    },
    "message": "",
    "status": 200
}

Command Line Options & CFG files

To be documented

Pipes & Async Pipes

To be documented

Error Reporting

To be documented

Accessing Request Arguments

To be documented

... Working on Documentation, Should be available soon ...

Documentation

Index

Constants

View Source
const ERROR = "An Internal Error has occured while processing this Request." +
	"If you believe this is an Error, please contact support team."
View Source
const PAGE_SIZE = 30
View Source
const SKIP = 0

Variables

View Source
var SysInitChan = make(chan bool, 1)

Functions

func BindHandlers

func BindHandlers(urls []*Url)

func DefaultServer

func DefaultServer()

func ErrorTemplate

func ErrorTemplate(stack string, traceback string) string

func Exception

func Exception(req *Request)

func MakeServer

func MakeServer(cfg conf.Configurer)

Types

type HttpError

type HttpError struct {
	Status  int
	Message string
}

func (HttpError) SendOverWire

func (e HttpError) SendOverWire() utils.Q

type MailConn

type MailConn struct {
	Hostname   string
	Username   string
	Password   string
	SenderName string
	Port       string
	Host       string
}

func MakeConn

func MakeConn() *MailConn

func (*MailConn) MessageBytes

func (conn *MailConn) MessageBytes(message Message) []byte

func (*MailConn) SendEmail

func (conn *MailConn) SendEmail(message Message)

type Message

type Message struct {
	From    string
	To      []string
	Subject string
	Body    string
}

type Paginator

type Paginator struct {
	Skip  int
	Limit int
	Wlt   string
	Wgt   string
	Wkey  string
	Ids   []string
}

type Request

type Request struct {
	Request    *http.Request
	Writer     http.ResponseWriter
	UrlArgs    *map[string]string
	PipeOutput *[]utils.Q
	PipeIndex  int
	// contains filtered or unexported fields
}

func (*Request) ConvertArgument

func (r *Request) ConvertArgument(key string, f interface{})

func (*Request) ConvertArguments

func (r *Request) ConvertArguments(f interface{})

func (*Request) GetArgument

func (r *Request) GetArgument(key string) interface{}

func (*Request) GetArguments

func (r *Request) GetArguments() *utils.Q

func (*Request) GetPaginator

func (r *Request) GetPaginator() *Paginator

func (*Request) Raise

func (r *Request) Raise(e HttpError)

func (*Request) Write

func (r *Request) Write(data interface{})

type Url

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

func NewUrl

func NewUrl(name string, pattern string, handler func(r *Request)) *Url

func (Url) MakeUrlArgs

func (u Url) MakeUrlArgs(url *string) (*map[string]string, bool)

type WireSender

type WireSender interface {
	SendOverWire() utils.Q
}

Directories

Path Synopsis
tests

Jump to

Keyboard shortcuts

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