urlshort

package
v0.0.0-...-f717e8e Latest Latest
Warning

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

Go to latest
Published: May 5, 2020 License: MIT Imports: 6 Imported by: 0

README

gophercises

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareInsensitive

func CompareInsensitive(a, b string) bool

Pseudo code

func DBHandler

func DBHandler(selectionFunction HandlerSelectionFunction, fallback Handler, fallbackLocation string) (HandlerFunc, error)

func DefaultMux

func DefaultMux(fallbackLocation string) *ServeMux

func MapHandler

func MapHandler(dataStore interface{}, selectionFunction HandlerSelectionFunction, fallback Handler, fallbackLocation string) HandlerFunc

MapHandler will return an http.HandlerFunc (which also implements http.Handler) that will attempt to map any paths (keys in the map) to their corresponding URL (values that each key in the map points to, in string format). If the path is not provided in the map, then the fallback http.Handler will be called instead.

func SelectHandler

func SelectHandler(reqPath string, dataStore interface{}, tableName string, fallbackHandler Handler, fallbackLocation string) (Handler, string)

NOTES: 1) Too many params 2) tableName is not needed in info in string map and not in DB

func YAMLHandler

func YAMLHandler(yaml []byte, selectionFunction HandlerSelectionFunction, fallback Handler, fallbackLocation string) (HandlerFunc, error)

YAMLHandler will parse the provided YAML and then return an http.HandlerFunc (which also implements http.Handler) that will attempt to map any paths to their corresponding URL. If the path is not provided in the YAML, then the fallback http.Handler will be called instead.

YAML is expected to be in the format:

The only errors that can be returned all related to having invalid YAML data.

See MapHandler to create a similar http.HandlerFunc via a mapping of paths to urls.

Types

type HandlerSelectionFunction

type HandlerSelectionFunction func(string, interface{}, Handler, string) (Handler, string)

func CreateSelectionFunction

func CreateSelectionFunction(tableName string) HandlerSelectionFunction

NOTE: tableName has nothing to do with the purpose of the function

type ServerWriter

type ServerWriter struct {
	// contains filtered or unexported fields
}

func (*ServerWriter) Header

func (s *ServerWriter) Header() http.Header

func (*ServerWriter) Write

func (s *ServerWriter) Write(b []byte) (int, error)

func (*ServerWriter) WriteHeader

func (s *ServerWriter) WriteHeader(code int) http.Header

type YamlConfig

type YamlConfig struct {
	Mappings []YamlMapping `yaml:mappings`
}

type YamlMapping

type YamlMapping struct {
	Path string
	Url  string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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