http

package
v0.0.0-...-b9a316c Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package http implements the HTTP interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	Google string
}

Auth contains the values stored in the cookie for auth-related actions.

type Database

type Database interface {
	CreateUser(*model.User) error
	UpdateUser(*model.User) error
	UpdateUserUsername(username string, u *model.User) error
	GetUser(username string) (*model.User, error)

	CreateLink(*model.Link, *model.User) error
	IncrementLinkCount(*model.Link)
	UpdateLinkSlug(slug string, l *model.Link, u *model.User) error
	GetLinks(slugs []string) ([]*model.Link, error)
	GetLink(slug string) (*model.Link, error)
	DeleteLink(*model.Link, *model.User) error

	UpdateAuths([]*model.Auth, *model.Link) error
	GetAuths(ids []string) ([]*model.Auth, error)
}

Database represents the database.

type Flash

type Flash struct {
	Success string
	Failure string
}

Flash is the flash stored in the cookie.

type Server

type Server struct {
	Port               string
	Hostname           string
	AuthSecret         string
	CookieHashKey      string
	CookieBlockKey     string
	GoogleClientID     string
	GoogleClientSecret string
	Logger             logrus.FieldLogger
	Database           Database
	// contains filtered or unexported fields
}

Server serves the website.

func (*Server) Auth

func (s *Server) Auth(w http.ResponseWriter, r *http.Request) (Auth, error)

Auth retrieves the auth saved in the cookie and removes it.

func (*Server) AuthGoogle

func (s *Server) AuthGoogle(w http.ResponseWriter, r *http.Request)

AuthGoogle authenticates the user with Google and redirects back to the link.

func (*Server) Cookie

func (s *Server) Cookie(r *http.Request, key string, value interface{}) error

Cookie returns the cookie from the request.

func (s *Server) CreateLink(w http.ResponseWriter, r *http.Request)

CreateLink shortens the URL and creates the resulting link.

func (*Server) CreateUser

func (s *Server) CreateUser(w http.ResponseWriter, r *http.Request)

CreateUser attempts to create the user.

func (*Server) CreateUserForm

func (s *Server) CreateUserForm(w http.ResponseWriter, r *http.Request)

CreateUserForm renders the user creation form.

func (*Server) DeleteCookie

func (s *Server) DeleteCookie(w http.ResponseWriter, key string)

DeleteCookie deletes the cookie in the response.

func (s *Server) DeleteLink(w http.ResponseWriter, r *http.Request)

DeleteLink deletes the link.

func (*Server) Flash

func (s *Server) Flash(w http.ResponseWriter, r *http.Request) (Flash, error)

Flash retrieves the flash saved in the cookie and removes it.

func (*Server) Index

func (s *Server) Index(w http.ResponseWriter, r *http.Request)

Index renders the index page.

func (s *Server) Link(r *http.Request) *model.Link

Link returns the link for the given request.

func (*Server) Listen

func (s *Server) Listen() error

Listen listens for requests, blocking until an error occurs.

func (*Server) Login

func (s *Server) Login(w http.ResponseWriter, r *http.Request)

Login attempts to log the user in.

func (*Server) LoginForm

func (s *Server) LoginForm(w http.ResponseWriter, r *http.Request)

LoginForm renders the login form.

func (*Server) Logout

func (s *Server) Logout(w http.ResponseWriter, r *http.Request)

Logout logs the user out.

func (*Server) Redirect

func (s *Server) Redirect(w http.ResponseWriter, r *http.Request)

Redirect redirects to the corresponding page from the slug.

func (s *Server) RequireLink(next http.Handler) http.Handler

RequireLink checks if the user is authorized to access the link.

Must be placed after SetLogger, SetUser and SetLink.

func (*Server) Router

func (s *Server) Router() chi.Router

Router mounts all routes on a router and returns it.

func (*Server) SetAuth

func (s *Server) SetAuth(w http.ResponseWriter, a Auth) error

SetAuth sets the auth in the cookie to be used on the next request.

func (*Server) SetCookie

func (s *Server) SetCookie(w http.ResponseWriter, key string, value interface{}) error

SetCookie sets a cookie in the response.

func (*Server) SetFlash

func (s *Server) SetFlash(w http.ResponseWriter, f Flash) error

SetFlash sets the flash in the cookie to be used on the next request.

func (s *Server) SetLink(next http.Handler) http.Handler

SetLink sets the link in the context.

Must be placed after SetLogger.

func (*Server) SetUser

func (s *Server) SetUser(next http.Handler) http.Handler

SetUser sets the user in the context, creating an anonymous one if not found.

Must be placed after SetLogger.

func (s *Server) UpdateLink(w http.ResponseWriter, r *http.Request)

UpdateLink updates the link.

func (*Server) UpdateLinkForm

func (s *Server) UpdateLinkForm(w http.ResponseWriter, r *http.Request)

UpdateLinkForm renders to form to update the link.

func (*Server) UpdateUser

func (s *Server) UpdateUser(w http.ResponseWriter, r *http.Request)

UpdateUser attempts to update the user.

func (*Server) UpdateUserForm

func (s *Server) UpdateUserForm(w http.ResponseWriter, r *http.Request)

UpdateUserForm renders the user update form.

func (*Server) User

func (s *Server) User(r *http.Request) *model.User

User returns the user for the given request.

Directories

Path Synopsis
Package middleware defines some generic middleware.
Package middleware defines some generic middleware.

Jump to

Keyboard shortcuts

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