Auth0

package
v0.0.0-...-c4bd2fe Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddFeedbackHandler = http.HandlerFunc(
	func(w http.ResponseWriter, r *http.Request) {
		var product Product
		vars := mux.Vars(r)
		slug := vars["slug"]

		for _, p := range products {
			if p.Slug == slug {
				product = p

			}

		}

		w.Header().Set("Content-Type", "application/json")
		if product.Slug != "" {
			payload, _ := json.Marshal(product)
			w.Write([]byte(payload))

		} else {
			w.Write([]byte("Product Not Found"))

		}
	})

The feedback handler will add either positive or negative feedback to the product

We would normally save this data to the database - but for this demo we'll fake it
so that as long as the request is successful and we can match a product to our catalog of products
we'll return an OK status.
View Source
var GetTokenHandler = http.HandlerFunc(
	func(w http.ResponseWriter, r *http.Request) {

		token := jwt.New(jwt.SigningMethodHS256)

		token.Claims["admin"] = true
		token.Claims["name"] = "Ado Kukic"
		token.Claims["exp"] = time.Now().Add(time.Hour * 24).Unix()

		tokenString, _ := token.SignedString(mySigningKey)

		w.Write([]byte(tokenString))
	})
View Source
var NotImplemented = http.HandlerFunc(
	func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Not Implemented"))
	})

Here we are implementing the NotImplemented handler. Whenever an API endpoint is hit we will simply return the message "Not Implemented"

View Source
var ProductsHandler = http.HandlerFunc(
	func(w http.ResponseWriter, r *http.Request) {

		payload, _ := json.Marshal(products)

		w.Header().Set("Content-Type", "application/json")
		w.Write([]byte(payload))
	})
The products handler will be called when the user makes a GET request to the /products endpoint.

This handler will return a list of products available for users to review

View Source
var StatusHandler = http.HandlerFunc(
	func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("API is up and running"))
	})

Handlers The status handler will be invoked when the user calls the /status route

It will simply return a string with the message "API is up and running"

Functions

This section is empty.

Types

type Product

type Product struct {
	Id          int
	Name        string
	Slug        string
	Description string
}

We will first create a new type called Product

This type will contain information about VR experiences

Jump to

Keyboard shortcuts

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