rest

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DebugAccessCallback

func DebugAccessCallback(token string, ip string, resource string, id string) bool

DebugAccessCallback returns the global variable debugAccessSuccess. It will log the arguments to the package logger in debug level.

Example
err := StartSimpleService(":8080", "/", "123", DebugAccessCallback)
if err != nil {
	// handle error
}

func FullAccessCallback

func FullAccessCallback(_ string, _ string, _ string, _ string) bool

FullAccessCallback will grant access to every rest request.

Example
err := StartSimpleService(":8080", "/", "123", FullAccessCallback)
if err != nil {
	// handle error
}

func StartMultiService

func StartMultiService(bindAddress string, prefix string, key string, callback TestAccessFunc) error

StartMultiService creates a multi password rest service. The service binds to "/prefix/overwrite" (PUT), "/prefix/get" (GET), "/prefix/check" (GET), "/prefix/set" (PUT), "/prefix/unset" (DELETE), "/prefix/list" (GET), "/prefix/delete" (DELETE), "/prefix/clean" (DELETE). The callback of type TestAccessFunc will be called for every request to determine access.

Example
// Start rest service on localhost:8080 without any access control.
err := StartMultiService(":8080", "/prefix", "123", func(string, string, string, string) bool { return true })
if err != nil {
	// handle error
}

func StartSimpleService

func StartSimpleService(bindAddress string, prefix string, key string, callback TestAccessFunc) error

StartSimpleService creates a single password rest service. The service binds to "/prefix/overwrite" (PUT), "/prefix/get" (GET), "/prefix/check" (GET), "/prefix/set" (PUT), "/prefix/unset" (DELETE), "/prefix/delete" (DELETE). The callback of type TestAccessFunc will be called for every request to determine access.

Example
// Start rest service on localhost:8080 without any access control.
err := StartSimpleService(":8080", "/prefix", "123", func(string, string, string, string) bool { return true })
if err != nil {
	// handle error
}

func StopService

func StopService(timeout int) error

StopService will block execution and try to gracefully shut down any rest service during the timeout period. The service is guaranteed to be closed at the end of the timeout.

Types

type TestAccessFunc

type TestAccessFunc func(token string, ip string, resource string, id string) bool

TestAccessFunc is a callback signature. The callback will be called by the rest service for every request to determine access based on the accessToken.

Jump to

Keyboard shortcuts

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