goneshot

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2022 License: MIT Imports: 6 Imported by: 0

README

WIP


func register(w http.ResponseWriter, r *http.Request) {
	client := r.URL.Query().Get("client")
	validToken, err := GetJWT(client)
	if err != nil {
		fmt.Println("Failed to generate token")
	}

	fmt.Fprint(w, string(validToken))
}

func secretPage(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Super Secret test Information")
}

func handleRequests() {
	http.HandleFunc("/", register)
	http.Handle("/check", isAuthorized(secretPage))
    
	log.Fatal(http.ListenAndServe(":8080", nil))
}

func main() {
	handleRequests()
}


Documentation

Index

Constants

This section is empty.

Variables

View Source
var IsAuthorized = func(endpoint func(http.ResponseWriter, *http.Request)) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if r.Header["Token"] != nil {
			validToken, err := validateToken(w, r)

			if err != nil {
				fmt.Fprint(w, err.Error())
			}

			if validToken {
				endpoint(w, r)
			}
		} else {
			fmt.Fprintf(w, "No Authorization Token provided")
		}
	})
}

IsAuthorized is the middleware function to check if the request is authorized

Functions

func GetJWT

func GetJWT(client string) (string, error)

GetJWT generates a JWT token

Types

This section is empty.

Jump to

Keyboard shortcuts

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