Categorygithub.com/fromkeith/gorest
modulepackage
0.0.0-20150514202557-ee389d6398d5
Repository: https://github.com/fromkeith/gorest.git
Documentation: pkg.go.dev

# README

gorest

A fork of http://code.google.com/p/gorest/

Documentation: http://godoc.org/github.com/fromkeith/gorest

This Fork

This fork changes the following:

  • Response marshallers return the type io.Reader instead of []byte. (Breaking change)
  • RegisterRecoveryHandler(handler) added. This allows runtime errors to be handled by the user of the library.
  • OverrideLogger(logger) added. Allows the logger used in gorest to be overridden
  • RegisterHealthHandler(handler) added. Allows health info (status codes) to be more easily reported.
  • Individual endpoints can now specify their own 'produces' tag. So you can have 1 service output many data types.
  • Allow Put, Post and Delete requests to return data in the body.
  • Applied some enforcement on the 'output' tag, to ensure it is specified. (Unknown if this will break people)
  • Generates documentation on your services. See DocumentServices for more info.
  • Allows you to redefine default result codes. So if you want 200 for POST you can now set that.

License

Original code is from: http://code.google.com/p/gorest/ Please see their license and headers in files.

Modified code is licensed as:

Copyright (c) 2014, fromkeith All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the fromkeith nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Functions

No description provided by the author
This is the default and exmaple authorizer that is used to authorize requests to endpints with no security realms.It always allows access and returns nil for SessionData.
Creates HTML documents of all the registered services and authorizers.
Returns the registred Authorizer for the specified realm.
Get an already registered Marshaller.
No description provided by the author
Registeres the function to be used for handling all requests directed to gorest.
Marshals the data in interface i into a byte slice, using the Marhaller/Unmarshaller specified in mime.The Marhaller/Unmarshaller must have been registered before using gorest.RegisterMarshaller.
Marshals the data in interface i into a byte slice, using the Marhaller/Unmarshaller specified in mime.The Marhaller/Unmarshaller must have been registered before using gorest.RegisterMarshaller.
application/x-www-form-urlencoded.
JSON: This makes the JSON Marshaller.
This creates a new RequestBuilder, backed by GoRest's internally managed http.Client.Although http.Client is useable concurrently, an instance of RequestBuilder is not safe for this.
Use this if you have a *http.Client instance that you specifically want to use.
application/x-www-form-urlencoded.
XML.
Overrides the logger with your own version.
Registers the handler to deal with health information.
Register a Marshaller.
Registers an Authorizer for the specified realm.
Register a callback that will be fired whenever gorest runs into a runtime error.
Registeres a service on the rootpath.See example below: package main import ( "code.google.com/p/gorest" "http" ) func main() { gorest.RegisterService(new(HelloService)) //Register our service http.Handle("/",gorest.Handle()) http.ListenAndServe(":8787",nil) } //Service Definition type HelloService struct { gorest.RestService `root:"/tutorial/"` helloWorld gorest.EndPoint `method:"GET" path:"/hello-world/" output:"string"` sayHello gorest.EndPoint `method:"GET" path:"/hello/{name:string}" output:"string"` } func(serv HelloService) HelloWorld() string{ return "Hello World" } func(serv HelloService) SayHello(name string) string{ return "Hello " + name }.
Registeres a service under the specified path.See example below: package main import ( "code.google.com/p/gorest" "http" ) func main() { gorest.RegisterServiceOnPath("/rest/",new(HelloService)) //Register our service http.Handle("/",gorest.Handle()) http.ListenAndServe(":8787",nil) } //Service Definition type HelloService struct { gorest.RestService `root:"/tutorial/"` helloWorld gorest.EndPoint `method:"GET" path:"/hello-world/" output:"string"` sayHello gorest.EndPoint `method:"GET" path:"/hello/{name:string}" output:"string"` } func(serv HelloService) HelloWorld() string{ return "Hello World" } func(serv HelloService) SayHello(name string) string{ return "Hello " + name }.
Runs the default "net/http" DefaultServeMux on the specified port.All requests are handled using gorest.HandleFunc().
No description provided by the author
If a handler is still handling a request after the specified duration, the health handler's ReportLongCall method will be invoked.
Unmarshals the data in buf into interface i, using the Marhaller/Unmarshaller specified in mime.The Marhaller/Unmarshaller must have been registered before using gorest.RegisterMarshaller.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
POST
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
A Marshaller represents the two functions used to marshal/unmarshal interfaces back and forth.
No description provided by the author
Facilitates the construction of the response to be sent to the client.
Used to declare a new service.

# Interfaces

No description provided by the author
HealthHandler reports some overal health information about requests.
Interface to be implemented by any session storage mechanism to be used with authorization.
A simple interface to wrap a basic leveled logger.

# Type aliases

Signiture of functions to be used as Authorizers.
Used to declare and EndPoint, wich represents a single point of entry to gorest applications, via a URL.See code example below: type HelloService struct { gorest.RestService `root:"/tutorial/"` helloWorld gorest.EndPoint `method:"GET" path:"/hello-world/" output:"string"` sayHello gorest.EndPoint `method:"GET" path:"/hello/{name:string}" output:"string"` } .
The request's response writter and request body.