hyper

package module
v0.0.0-...-77132cc Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2018 License: MIT Imports: 21 Imported by: 0

README

hyper

HTTP web framework with DataLoader, GraphQL and Swagger integration

Feature

  • HTTP 2
  • Websocket
  • GraphQL + Subscription
  • Dataloader
  • Swagger

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

License

This project is distributed under the MIT license found in the LICENSE file.

The MIT License (MIT)

Copyright (c) 2018 Sam

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Documentation

Index

Constants

View Source
const (
	Any             = router.Any
	Text            = router.Text
	Int             = router.Int
	I32             = router.I32
	I64             = router.I64
	U32             = router.U32
	U64             = router.U64
	F32             = router.F32
	F64             = router.F64
	Bool            = router.Bool
	Lat             = router.Lat
	Lon             = router.Lon
	Json            = router.Json
	Email           = router.Email
	URL             = router.URL
	UUID            = router.UUID
	File            = router.File
	DateTimeRFC822  = router.DateTimeRFC822
	DateTimeRFC3339 = router.DateTimeRFC3339
	DateTimeUnix    = router.DateTimeUnix
)
View Source
const (
	StatusContinue                     = 100
	StatusSwitchingProtocols           = 101
	StatusOK                           = 200
	StatusCreated                      = 201
	StatusAccepted                     = 202
	StatusNonAuthoritativeInfo         = 203
	StatusNoContent                    = 204
	StatusResetContent                 = 205
	StatusPartialContent               = 206
	StatusMultipleChoices              = 300
	StatusMovedPermanently             = 301
	StatusFound                        = 302
	StatusSeeOther                     = 303
	StatusNotModified                  = 304
	StatusUseProxy                     = 305
	StatusTemporaryRedirect            = 307
	StatusBadRequest                   = 400
	StatusUnauthorized                 = 401
	StatusPaymentRequired              = 402
	StatusForbidden                    = 403
	StatusNotFound                     = 404
	StatusMethodNotAllowed             = 405
	StatusNotAcceptable                = 406
	StatusProxyAuthRequired            = 407
	StatusRequestTimeout               = 408
	StatusConflict                     = 409
	StatusGone                         = 410
	StatusLengthRequired               = 411
	StatusPreconditionFailed           = 412
	StatusRequestEntityTooLarge        = 413
	StatusRequestURITooLong            = 414
	StatusUnsupportedMediaType         = 415
	StatusRequestedRangeNotSatisfiable = 416
	StatusExpectationFailed            = 417
	StatusTeapot                       = 418
	StatusInternalServerError          = 500
	StatusNotImplemented               = 501
	StatusBadGateway                   = 502
	StatusServiceUnavailable           = 503
	StatusGatewayTimeout               = 504
	StatusHTTPVersionNotSupported      = 505
)

HTTP Status

Variables

View Source
var GQLBodies = []router.Param{
	Body("query").
		Format(Text).
		Require(false),
	Body("variables").
		Format(Text).
		Require(false),
}

GQLBodies parameters

View Source
var GQLQueries = []router.Param{
	Query("query").
		Format(Text).
		Require(false),
	Query("variables").
		Format(Text).
		Require(false),
}

GQLQueries parameters

Functions

func Body

func Body(name string) router.Param

Body func

func Context

func Context(c context.Context) router.Context

Context reads router context from context.Context

func Cookie(name string) router.Param

Cookie func

func GraphQL

func GraphQL(schema graphql.Schema) router.HandlerFunc

GraphQL handles graphql

func GraphiQL

func GraphiQL() router.HandlerFunc

GraphiQL renders graphiql interface

func Header(name string) router.Param

Header func

func Model

func Model(code int, response interface{}) router.Model

Model func

func OneOf

func OneOf(ps ...router.Param) router.Param

OneOf group func

func Param

func Param(name string) router.Param

Param func

func Query

func Query(name string) router.Param

Query func

Types

type Hyper

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

Hyper service

func New

func New(opts ...Option) *Hyper

New creates a hyper server

func (*Hyper) Gws

func (v *Hyper) Gws() gws.Service

Gws returns graphql subscription service

func (*Hyper) Router

func (v *Hyper) Router() router.Service

Router returns router service

func (*Hyper) Run

func (v *Hyper) Run() error

Run hyper server

func (*Hyper) String

func (v *Hyper) String() string

String returns hyper server in string

func (*Hyper) Sync

func (v *Hyper) Sync() sync.Service

Sync returns sync service

type Option

type Option func(*Options)

Option func

func Addr

func Addr(s string) Option

Addr to change server bind address

func AfterStop

func AfterStop(f func() error) Option

AfterStop to add after stop action to hyper server

func AllowCredentials

func AllowCredentials(b bool) Option

func AllowOriginFunc

func AllowOriginFunc(f func(string) bool) Option

func AllowedHeaders

func AllowedHeaders(a []string) Option

func AllowedMethods

func AllowedMethods(a []string) Option

func AllowedOrigins

func AllowedOrigins(a []string) Option

func BeforeStart

func BeforeStart(f func() error) Option

BeforeStart to add before start action to hyper server

func Cache

func Cache(c cache.Service) Option

Cache to set custom cache engine

func DataLoader

func DataLoader(d dataloader.Service) Option

DataLoader to set custom dataloader

func ExposedHeaders

func ExposedHeaders(a []string) Option

func HTTP

func HTTP() Option

HTTP to use 1.1 network protocol

func HTTP2

func HTTP2() Option

HTTP2 to use 2.0 network protocol

func ID

func ID(s string) Option

ID to change server reference id

func MaxAge

func MaxAge(i int) Option

func Message

func Message(m message.Service) Option

Message to set custom message broker

func OptionsPassthrough

func OptionsPassthrough(b bool) Option

func Router

func Router(r router.Service) Option

Router to set custom router

func Sync

func Sync(s sync.Service) Option

Sync to set custom sync engine

type Options

type Options struct {

	// hyper server unique id
	ID string

	// server bind to address [host:port]
	Addr string

	// HTTP protocol 1.1 / 2.0
	Protocol engine.Protocol

	// sync engine
	Sync sync.Service

	// graphql subscription engine
	GQLSubscription gws.Service

	// Cache engine
	Cache cache.Service

	// Router
	Router router.Service

	// Message broker
	Message message.Service

	// DataLoader
	DataLoader dataloader.Service

	// before and after funcs
	BeforeStart []func() error
	AfterStop   []func() error

	// AllowedOrigins is a list of origins a cross-domain request can be executed from.
	// If the special "*" value is present in the list, all origins will be allowed.
	// An origin may contain a wildcard (*) to replace 0 or more characters
	// (i.e.: http://*.domain.com). Usage of wildcards implies a small performance penality.
	// Only one wildcard can be used per origin.
	// Default value is ["*"]
	AllowedOrigins []string

	// AllowOriginFunc is a custom function to validate the origin. It take the origin
	// as argument and returns true if allowed or false otherwise. If this option is
	// set, the content of AllowedOrigins is ignored.
	AllowOriginFunc func(origin string) bool

	// AllowedMethods is a list of methods the client is allowed to use with
	// cross-domain requests. Default value is simple methods (GET and POST)
	AllowedMethods []string

	// AllowedHeaders is list of non simple headers the client is allowed to use with
	// cross-domain requests.
	// If the special "*" value is present in the list, all headers will be allowed.
	// Default value is [] but "Origin" is always appended to the list.
	AllowedHeaders []string

	// ExposedHeaders indicates which headers are safe to expose to the API of a CORS
	// API specification
	ExposedHeaders []string

	// AllowCredentials indicates whether the request can include user credentials like
	// cookies, HTTP authentication or client side SSL certificates.
	AllowCredentials bool

	// MaxAge indicates how long (in seconds) the results of a preflight request
	// can be cached
	MaxAge int

	// OptionsPassthrough instructs preflight to let other potential next handlers to
	// process the OPTIONS method. Turn this on if your application handles OPTIONS.
	OptionsPassthrough bool
}

Options is the hyper server options

type Payload

type Payload struct {
	RawQuery        string                 `json:"-"`
	RawVariables    string                 `json:"-"`
	ParsedQuery     string                 `json:"query"`
	ParsedVariables map[string]interface{} `json:"variables"`
}

Payload struct

func (*Payload) Parse

func (v *Payload) Parse()

Parse to read raw query and variables

Directories

Path Synopsis
Package dataloader source: https://github.com/nicksrandall/dataloader dataloader is an implimentation of facebook's dataloader in go.
Package dataloader source: https://github.com/nicksrandall/dataloader dataloader is an implimentation of facebook's dataloader in go.
examples
gql
Package gws is a generated protocol buffer package.
Package gws is a generated protocol buffer package.
Package sync is a generated protocol buffer package.
Package sync is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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