Documentation ¶
Overview ¶
Package http implements the HTTP interface.
Index ¶
- type Auth
- type Database
- type Flash
- type Server
- func (s *Server) Auth(w http.ResponseWriter, r *http.Request) (Auth, error)
- func (s *Server) AuthGoogle(w http.ResponseWriter, r *http.Request)
- func (s *Server) Cookie(r *http.Request, key string, value interface{}) error
- func (s *Server) CreateLink(w http.ResponseWriter, r *http.Request)
- func (s *Server) CreateUser(w http.ResponseWriter, r *http.Request)
- func (s *Server) CreateUserForm(w http.ResponseWriter, r *http.Request)
- func (s *Server) DeleteCookie(w http.ResponseWriter, key string)
- func (s *Server) DeleteLink(w http.ResponseWriter, r *http.Request)
- func (s *Server) Flash(w http.ResponseWriter, r *http.Request) (Flash, error)
- func (s *Server) Index(w http.ResponseWriter, r *http.Request)
- func (s *Server) Link(r *http.Request) *model.Link
- func (s *Server) Listen() error
- func (s *Server) Login(w http.ResponseWriter, r *http.Request)
- func (s *Server) LoginForm(w http.ResponseWriter, r *http.Request)
- func (s *Server) Logout(w http.ResponseWriter, r *http.Request)
- func (s *Server) Redirect(w http.ResponseWriter, r *http.Request)
- func (s *Server) RequireLink(next http.Handler) http.Handler
- func (s *Server) Router() chi.Router
- func (s *Server) SetAuth(w http.ResponseWriter, a Auth) error
- func (s *Server) SetCookie(w http.ResponseWriter, key string, value interface{}) error
- func (s *Server) SetFlash(w http.ResponseWriter, f Flash) error
- func (s *Server) SetLink(next http.Handler) http.Handler
- func (s *Server) SetUser(next http.Handler) http.Handler
- func (s *Server) UpdateLink(w http.ResponseWriter, r *http.Request)
- func (s *Server) UpdateLinkForm(w http.ResponseWriter, r *http.Request)
- func (s *Server) UpdateUser(w http.ResponseWriter, r *http.Request)
- func (s *Server) UpdateUserForm(w http.ResponseWriter, r *http.Request)
- func (s *Server) User(r *http.Request) *model.User
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 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) 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) CreateLink ¶
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 (*Server) DeleteLink ¶
func (s *Server) DeleteLink(w http.ResponseWriter, r *http.Request)
DeleteLink deletes the link.
func (*Server) Index ¶
func (s *Server) Index(w http.ResponseWriter, r *http.Request)
Index renders the index page.
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 (*Server) RequireLink ¶
RequireLink checks if the user is authorized to access the link.
Must be placed after SetLogger, SetUser and SetLink.
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 (*Server) SetUser ¶
SetUser sets the user in the context, creating an anonymous one if not found.
Must be placed after SetLogger.
func (*Server) UpdateLink ¶
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.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package middleware defines some generic middleware.
|
Package middleware defines some generic middleware. |