internal

package
v0.0.0-...-f391ad9 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Log *logrus.Logger = newLogger()

Log is the logging object used by the binary.

Functions

func HTTPLogger

func HTTPLogger(inner http.Handler, name string) http.Handler

HTTPLogger returns a http.Handler that logs the http request.

func NewRouter

func NewRouter(serverAddress string, dbFile string) *mux.Router

NewRouter returns a new mux.Router that handles all incoming http requests. serverAddress: The server address the bookmarks server is running as.

E.g - https://bm.suram.in

Types

type AliasInfo

type AliasInfo struct {
	Alias string
	Orig  string
	// contains filtered or unexported fields
}

AliasInfo contains info about a shortened alias.

type ColInfo

type ColInfo struct {
	Name     string  `json:"name"`
	Label    string  `json:"label"`
	Datatype string  `json:"datatype"`
	Bar      bool    `json:"bar"`
	Editable bool    `json:"editable"`
	Values   *string `json:"values"`
}

ColInfo holds metadata for columns in the alias table showed in the UI.

type ErrStruct

type ErrStruct struct {
	Code int    `json:"code"`
	Text string `json:"text"`
}

ErrStruct holds an error message that can be converted to a json.

type Handlers

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

Handlers struct has methods to handle http requests to be served by the webserver.

func (*Handlers) ActionAdd

func (h *Handlers) ActionAdd(w http.ResponseWriter, r *http.Request)

ActionAdd handles http request to add a new bookmark.

func (*Handlers) ActionDel

func (h *Handlers) ActionDel(w http.ResponseWriter, r *http.Request)

ActionDel handles http request to add a delete bookmark.

func (*Handlers) ActionLookup

func (h *Handlers) ActionLookup(w http.ResponseWriter, r *http.Request)

ActionLookup handles http request to convert short url to the full url.

func (*Handlers) ActionRevLookup

func (h *Handlers) ActionRevLookup(w http.ResponseWriter, r *http.Request)

ActionRevLookup handles http request to convert full url to the short url.

func (*Handlers) ActionUpdate

func (h *Handlers) ActionUpdate(w http.ResponseWriter, r *http.Request)

ActionUpdate handles http request to add a update bookmark.

func (*Handlers) ActionView

func (h *Handlers) ActionView(w http.ResponseWriter, r *http.Request)

ActionView handles http request to view bookmarks list.

func (*Handlers) Redirect

func (h *Handlers) Redirect(w http.ResponseWriter, r *http.Request)

Redirect handles redirect for short url to full url.

type RevLookupResponse

type RevLookupResponse struct {
	ShortUrls []string `json:"shorturls"`
}

RevLookupResponse is response for RevLookup call.

type Row

type Row struct {
	ID     string  `json:"id"`
	Values RowInfo `json:"values"`
}

Row is a wrapper around RowInfo with an ID field.

type RowInfo

type RowInfo struct {
	Fullurl  string `json:"fullurl"`
	Alias    string `json:"alias"`
	Shorturl string `json:"shorturl"`
	Action   string `json:"action"`
}

RowInfo contains information for a singe alias row in the alias table.

type StorageInterface

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

StorageInterface is the interface to interact with the "storage layer" (i.e sqlite)

func NewStorageInterface

func NewStorageInterface(dbFile string) *StorageInterface

NewStorageInterface creates and initializes a new storage interface object.

func (*StorageInterface) AddAlias

func (s *StorageInterface) AddAlias(
	orig string, alias string, secret string) string

AddAlias adds an `alias` for `orig` url. Returns "ok" on success.

func (*StorageInterface) DelAlias

func (s *StorageInterface) DelAlias(alias string, secret string) string

DelAlias deletes the given `alias`. Returns "ok" on success.

func (*StorageInterface) GetAllAliases

func (s *StorageInterface) GetAllAliases(secret string) []AliasInfo

GetAllAliases gets all aliases. If the given secret matches the secret stored in db, then returns secret aliases as well.

func (*StorageInterface) GetShortUrls

func (s *StorageInterface) GetShortUrls(secret string, orig string) []string

GetShortUrls gets the short urls for the given full url. If secret matches the secret in db, then returns secret aliases as well.

func (*StorageInterface) URLFromAlias

func (s *StorageInterface) URLFromAlias(alias string) *string

URLFromAlias returns the full url for the given `alias`.

func (*StorageInterface) URLFromAliasTemplate

func (s *StorageInterface) URLFromAliasTemplate(expandedTemplate string) *string

func (*StorageInterface) UpdateAlias

func (s *StorageInterface) UpdateAlias(
	presAlias, oldVal, newVal, colname, secret string) string

UpdateAlias updates the alias for the given long url. Returns "ok" on success.

type ViewResponse

type ViewResponse struct {
	Data     []Row     `json:"data"`
	Metadata []ColInfo `json:"metadata"`
}

ViewResponse is response for View call.

func CreateViewResponse

func CreateViewResponse(aliases []AliasInfo, serverPrefix string) ViewResponse

CreateViewResponse creates viewResponse from the given aliases.

Jump to

Keyboard shortcuts

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