app

package
v0.0.0-...-48eb505 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package app serves the clamber package as an API.

Index

Constants

This section is empty.

Variables

View Source
var DefinedRoutes = Routes{
	Route{
		"Initiate",
		"GET",
		"/search",
		SearchHandler,
		[]string{
			"url", "{url}",
			"depth", "{depth}",
		},
	},
}

DefinedRoutes contains defined routes data

Functions

func HttpResponseLogger

func HttpResponseLogger(handler http.Handler) http.Handler

HttpResponseLogger creates a custom logger which outputs HTTP response info as a json log to stdout.

func InitFlags

func InitFlags(appFlags *Flags)

InitFlags loads flags into global var AppFlags

func NewRouter

func NewRouter() *mux.Router

NewRouter function initiates a mux router object with custom HTTP Response logger.

func SearchHandler

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

SearchHandler function handles /search endpoint. Initiates a database connection, tries to find the url in the database with the required depth, and if it doesn't exist, initiate a crawl.

Types

type Flags

type Flags struct {
	ConfigFile *string
	Port       *int
	Verbose    *bool
}

Flags holds the app Flags

var (
	// AppFlags makes a global Flag struct
	AppFlags Flags
)

type Query

type Query struct {
	Url          string       `json:"url"`
	Depth        int          `json:"depth"`
	DisplayDepth int          `json:"display_depth"`
	StatusCode   int          `json:"statusCode"`
	Results      *common.Page `json:"results"`
}

Query contains queried URL, depth and the resulting page data

type RichResponseWriter

type RichResponseWriter struct {
	http.ResponseWriter
	StatusCode int
}

RichResponseWriter encapsulates status code and Response Writer

func NewRichResponseWriter

func NewRichResponseWriter(w http.ResponseWriter) *RichResponseWriter

NewRichResponseWriter function creates a new RichResponseWriter

func (*RichResponseWriter) WriteHeader

func (w *RichResponseWriter) WriteHeader(code int)

WriteHeader function Writers specified header to response

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
	Queries     []string
}

Route contains all route data

type Routes

type Routes []Route

Routes is slice of Route

Jump to

Keyboard shortcuts

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