api

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleError

func HandleError(err error)

HandleError simply logs and exits the program if the error exists

func Hash

func Hash(s string) uint32

Hash generates a uint32 hash of a string

func Info

func Info(w http.ResponseWriter, r *http.Request)

Info simply returns a pretty ASCII art

func Starter

func Starter(url string) error

Starter starts the server

Types

type Config

type Config struct {
	//URL is the url for the dgraph database
	URL string
	// DBClient is the database client
	DBClient *db.ConfigDB
	// CacheDB is the cache client
	CacheDB *badger.DB
	// Lock is a global lock for database operations, just makes it a bit nicer.
	Lock *sync.Mutex
}

Config is the API configuration

func (*Config) GetCache

func (config *Config) GetCache(query string) (*string, error)

GetCache attempts to retrieve a cached version of the request

func (*Config) GetQuery

func (config *Config) GetQuery() func(w http.ResponseWriter, r *http.Request)

GetQuery performs a read only query without badger

func (*Config) PerformCachedQuery

func (config *Config) PerformCachedQuery(query string) (*string, error)

PerformCachedQuery is the main accessor with cache abilities

func (*Config) PerformQuery

func (config *Config) PerformQuery(query string) (*string, error)

PerformQuery is the main db accessor, without caching abilities.

func (*Config) Query

func (config *Config) Query() func(w http.ResponseWriter, r *http.Request)

Query performs a read only query

func (*Config) SetCache

func (config *Config) SetCache(query string, answer string) error

SetCache stores the query and answer in the database

func (*Config) SetupRouter

func (config *Config) SetupRouter() *mux.Router

SetupRouter returns a router with all the routes attached

type ErrorJSON

type ErrorJSON struct {
	Status, Error string
}

ErrorJSON is the response sent back in case of an error

Jump to

Keyboard shortcuts

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