resources

package
v0.0.0-...-789275d Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2017 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResponsePerPageName = "total"
	PerPageName         = "page"
)

contains specific constant names for usage in pkg.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	handlers.BearerAuth
	Next func(w http.ResponseWriter, r *http.Request, params map[string]string)
}

Auth defines an handler which provides authorization handling for a request, needing user authentication.

func (Auth) CheckAuthorization

func (u Auth) CheckAuthorization(w http.ResponseWriter, r *http.Request, params map[string]string)

CheckAuthorization handles receiving requests to verify user authorization.

Service API

HTTP Method: GET Header:

{
	"Authorization":"Bearer <TOKEN>",
}

WHERE: <TOKEN> = <USERID>:<SESSIONTOKEN>

type Guarded

type Guarded struct {
	SessionName  string
	CookieName   string
	CookieSecret string
	Cookies      sessions.CookieStore
	Log          sink.Sink
}

Guarded defines a struct which exposes a session secured request life cycle where a request made will be guarded with specific data from a underline session and will be validated when receiving response.

func (Guarded) Guard

func (u Guarded) Guard(w http.ResponseWriter, r *http.Request) error

Guard attempts to added incoming request with a session which is stored in the outgoing response which then will be used to guard against other incoming request.

func (Guarded) Validate

func (u Guarded) Validate(w http.ResponseWriter, r *http.Request) error

Validate attempts to authenticate incoming request with a sessio data expected from the request.

type OAuth

type OAuth struct {
	Auth    *auth.Auth
	Log     sink.Sink
	Options []oauth2.AuthCodeOption
}

OAuth defines a controller which handles the incoming request that it contains the giving "secret" within it's data.

func (*OAuth) Redirect

func (u *OAuth) Redirect(secret string, w http.ResponseWriter, r *http.Request) (string, error)

Redirect attempts to redirect incoming request with the OAuth URL from the supplied OAuth structure and uses the giving secret state to generate the URL to redirect to.

func (*OAuth) Validate

func (u *OAuth) Validate(secret string, w http.ResponseWriter, r *http.Request) error

Validate that the giving SecretCode matches the incoming value of the request else returns an error.

type Profiles

type Profiles struct {
	handlers.Profiles
	Users    handlers.Users
	Sessions handlers.Sessions
}

Profiles exposes a central handle for which the API exposes request for profiles.

func (Profiles) Create

func (u Profiles) Create(w http.ResponseWriter, r *http.Request, params map[string]string)

Create handles receiving requests to create a user from the server.

 Service API
	HTTP Method: POST
	Header:
			{
				"Authorization":"Bearer <TOKEN>",
			}

			WHERE: <TOKEN> = <USERID>:<SESSIONTOKEN>

	Request:
		Path: /profiles/
		Body:
			{
				"first_name":"",
				"last_name":"",
				"user_id":"",
				"email":"",
				"address":"",
			}

   Response: (Success, 200)
		Body:
			{
				"first_name":"",
				"last_name":"",
				"user_id":"",
				"public_id":"",
				"email":"",
				"address":"",
			}

   Response: (Failure, 500)
		Body:
			{
				"status":"",
				"title":"",
				"message":"",
			}

func (Profiles) Delete

func (u Profiles) Delete(w http.ResponseWriter, r *http.Request, params map[string]string)

Delete handles receiving requests to removes a user from the server.

 Service API
	HTTP Method: DELETE
	Header:
			{
				"Authorization":"Bearer <TOKEN>",
			}

			WHERE: <TOKEN> = <USERID>:<SESSIONTOKEN>

	Request:
		Path: /profile/:public_id
		Body: None

   Response: (Success, 201)
		Body: None

   Response: (Failure, 500)
	Body:
		{
			"status":"",
			"title":"",
			"message":"",
		}

func (Profiles) Get

func (u Profiles) Get(w http.ResponseWriter, r *http.Request, params map[string]string)

Get handles receiving requests to get a users from the db.

 Service API
	HTTP Method: GET
	Header:
			{
				"Authorization":"Bearer <TOKEN>",
			}

			WHERE: <TOKEN> = <USERID>:<SESSIONTOKEN>

	Request:
		Path: /profiles/:public_id
		Body: None

   Response: (Success, 200)
	Body:
		{
			"public_id":"",
			"private_id":"",
			"hash":"",
			"email":"",
		}

   Response: (Failure, 500)
	Body:
		{
			"status":"",
			"title":"",
			"message":"",
		}

func (Profiles) GetAll

func (u Profiles) GetAll(w http.ResponseWriter, r *http.Request, params map[string]string)

GetAll handles receiving requests to get all users from the db.

 Service API
	HTTP Method: GET
	Header:
			{
				"Authorization":"Bearer <TOKEN>",
			}

			WHERE: <TOKEN> = <USERID>:<SESSIONTOKEN>

	Request:
		Path: /admin/profiles/
		Body: None

   Response: (Success, 200)
	Body:
		{
			page: 1,
			total: 100,
			responsePerPage: 24,
			records: [{
				"first_name":"",
				"last_name":"",
				"user_id":"",
				"profile_id":"",
				"email":"",
				"address":"",
			}]
		}

   Response: (Failure, 500)
	Body:
		{
			"status":"",
			"title":"",
			"message":"",
		}

func (Profiles) GetForUser

func (u Profiles) GetForUser(w http.ResponseWriter, r *http.Request, params map[string]string)

GetForUser handles receiving requests to get a user's profile from the backend.

 Service API
	HTTP Method: GET
	Header:
			{
				"Authorization":"Bearer <TOKEN>",
			}

			WHERE: <TOKEN> = <USERID>:<SESSIONTOKEN>

	Request:
		Path: /profile/users/:user_id
		Body: None

   Response: (Success, 200)
	Body:
		{
			"public_id":"",
			"private_id":"",
			"hash":"",
			"email":"",
		}

   Response: (Failure, 500)
	Body:
		{
			"status":"",
			"title":"",
			"message":"",
		}

func (Profiles) Update

func (u Profiles) Update(w http.ResponseWriter, r *http.Request, params map[string]string)

Update handles receiving requests to update a user identified by it's public_id.

 Service API
	HTTP Method: PUT
	Header:
			{
				"Authorization":"Bearer <TOKEN>",
			}

			WHERE: <TOKEN> = <USERID>:<SESSIONTOKEN>

	Request:
		Path: /profile/:public_id
		Body:
			{
				"first_name":"",
				"last_name":"",
				"public_id":"",
				"email":"",
				"address":"",
			}

   Response: (Success, 201)
	Body: None

   Response: (Failure, 500)
	Body:
		{
			"status":"",
			"title":"",
			"message":"",
		}

type Sessions

type Sessions struct {
	handlers.Sessions
	Users handlers.Users
}

Sessions exposes a central handle for which requests are served to all requests.

func (Sessions) Get

func (s Sessions) Get(w http.ResponseWriter, r *http.Request, params map[string]string)

Get handles receiving requests to get a sessions from the db.

 Service API
	HTTP Method: GET
	Request:
		Path: /admin/sessions/:user_id
		Body: None

   Response: (Success, 200)
	Body:
		{
			"user_id":"",
			"public_id":"",
			"expires":"",
			"token":"",
		}

   Response: (Failure, 500)
	Body:
		{
			"status":"",
			"title":"",
			"message":"",
		}

func (Sessions) GetAll

func (s Sessions) GetAll(w http.ResponseWriter, r *http.Request, params map[string]string)

GetAll handles receiving requests to get all sessions from the db.

 Service API
	HTTP Method: GET
	Request:
		Path: /admin/sessions/
		Body: None

   Response: (Success, 200)
	Body:
		{
			page: 1,
			total: 100,
			responsePerPage: 24,
			records: [{
				"user_id":"",
				"public_id":"",
				"expires":"",
				"token":"",
			}]
		}

   Response: (Failure, 500)
	Body:
		{
			"status":"",
			"title":"",
			"message":"",
		}

func (Sessions) Login

func (s Sessions) Login(w http.ResponseWriter, r *http.Request, params map[string]string)

Login handles receiving requests to create a new session for a user from the server.

 Service API
	HTTP Method: POST
	Request:
		Path: /sessions/login
		Body:
			{
				"email": "",
				"password": ""
			}

   Response: (Success, 201)
		Body:
			{
				"type":"Bearer",
				"expires":"",
				"token":"",
			}

   Response: (Failure, 500)
	Body:
		`{
			"status":"",
			"title":"",
			"message":"",
		}

func (Sessions) Logout

func (s Sessions) Logout(w http.ResponseWriter, r *http.Request, params map[string]string)

Logout handles receiving requests to end a user session from the server.

 Service API
	HTTP Method: DELETE
	Header:
			{
				"Authorization":"Bearer <TOKEN>",
			}
	Request:
		Path: /sessions/logout/
		Body: None

   Response: (Success, 201)
		Body: None

   Response: (Failure, 500)
	Body:
		`{
			"status":"",
			"title":"",
			"message":"",
		}

func (Sessions) LogoutWithJSON

func (s Sessions) LogoutWithJSON(w http.ResponseWriter, r *http.Request, params map[string]string)

LogoutWithJSON handles receiving requests to end a user session from the server.

 Service API
	HTTP Method: DELETE
	Request:
		Path: /sessions/logout/
		Body:
			{
				"user_id": "",
				"token": ""
			}

   Response: (Success, 201)
		Body: None

   Response: (Failure, 500)
	Body:
		`{
			"status":"",
			"title":"",
			"message":"",
		}

type Users

type Users struct {
	handlers.Users
}

Users exposes a central handle for which requests are served to all requests.

func (Users) Create

func (u Users) Create(w http.ResponseWriter, r *http.Request, params map[string]string)

Create handles receiving requests to create a user from the server.

 Service API
	HTTP Method: POST
	Request:
		Path: /users/
		Body:
		{
			"password":"",
			"email":"",
		}

   Response: (Success, 200)
	Body:
		{
			"public_id":"",
			"email":"",
			"profile":"optional",
		}

   Response: (Failure, 500)
	Body:
		{
			"status":"",
			"title":"",
			"message":"",
		}

func (Users) Delete

func (u Users) Delete(w http.ResponseWriter, r *http.Request, params map[string]string)

Delete handles receiving requests to removes a user from the server.

 Service API
	HTTP Method: DELETE
	Request:
		Path: /users/:user_id
		Body: None

   Response: (Success, 201)
		Body: None

   Response: (Failure, 500)
	Body:
		{
			"status":"",
			"title":"",
			"message":"",
		}

func (Users) Get

func (u Users) Get(w http.ResponseWriter, r *http.Request, params map[string]string)

Get handles receiving requests to get a users from the db.

 Service API
	HTTP Method: GET
	Request:
		Path: /admin/users/:user_id
		Body: None

   Response: (Success, 200)
	Body:
		{
			"public_id":"",
			"private_id":"",
			"hash":"",
			"email":"",
		}

   Response: (Failure, 500)
	Body:
		{
			"status":"",
			"title":"",
			"message":"",
		}

func (Users) GetAll

func (u Users) GetAll(w http.ResponseWriter, r *http.Request, params map[string]string)

GetAll handles receiving requests to get all users from the db.

 Service API
	HTTP Method: GET
	Request:
		Path: /users
		Path: /users/:responser_per_page/:page
		Body: None

   Response: (Success, 200)
	Body:
		{
			page: 1,
			total: 100,
			responsePerPage: 24,
			records: [{
				"public_id":"",
				"private_id":"",
				"hash":"",
				"email":"",
			}]
		}

   Response: (Failure, 500)
	Body:
		{
			"status":"",
			"title":"",
			"message":"",
		}

func (Users) GetLimited

func (u Users) GetLimited(w http.ResponseWriter, r *http.Request, params map[string]string)

GetLimited handles receiving requests to get a user from the db but returns a limited view of the user data. This is suited for when needing to respond to requests from non-authorized requests or wishing to exclude security based fields (hash, private_id) from the response.

 Service API
	HTTP Method: GET
	Request:
		Path: /users/:user_id
		Body: None

   Response: (Success, 200)
	Body:
		{
			"public_id":"",
			"email":"",
		}

   Response: (Failure, 500)
	Body:
		{
			"status":"",
			"title":"",
			"message":"",
		}

func (Users) Update

func (u Users) Update(w http.ResponseWriter, r *http.Request, params map[string]string)

Update handles receiving requests to update a user identified by it's public_id.

 Service API
	HTTP Method: PUT
	Request:
		Path: /users/:user_id
		Body: None

   Response: (Success, 201)
	Body:
		{
			"public_id":"",
			"email":"",
		}

   Response: (Failure, 500)
	Body:
		{
			"status":"",
			"title":"",
			"message":"",
		}

func (Users) UpdatePassword

func (u Users) UpdatePassword(w http.ResponseWriter, r *http.Request, params map[string]string)

UpdatePassword handles receiving requests to update a user identified by it's public_id.

 Service API
	HTTP Method: PUT
	Request:
		Path: /users/password/:user_id
		Body: None
			{
				"public_id":"",
				"password":"",
				"password_confirmation":"",
			}

   Response: (Success, 201)
		Body: None

   Response: (Failure, 500)
	Body:
		{
			"status":"",
			"title":"",
			"message":"",
		}

Jump to

Keyboard shortcuts

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