server

package
v0.0.0-...-5b64ff3 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2022 License: MPL-2.0 Imports: 20 Imported by: 0

README

Server Docs

Routing

/api    => see API
GET /@  => index.html
GET /   => FileServer

API

/api
--> POST /signup    => see signup
--> POST /login     => see login
--> GET /chats      => see chats
--> GET /profile    => see profile
/signup

Request:

{
  "handle": "...",
  "name": "...",
  "password": "***"
}

Response is a simple string message. It is simply to be displayed to the user. Here's the table of possible status codes and their semantics:

Status Description
500 Internal server error Usually due to failed password hashing
409 Conflict Username is taken
200 OK Success
/login

Request:

{
  "handle": "...",
  "password": "***"
}

Response is a simple string message. It is simply to be displayed to the user. In case of a successful login, response will also contain a cookie with a JWT token for further communication. Here's the table of possible status codes and their semantics:

Status Description
404 Not found Username does not exist in the database
401 Unauthorized Invalid password
500 Internal server error Failed to generate a JWT token
200 OK Success
/chats

Request to chats is a plain GET with no data whatsoever. User's identity is established from their JWT token that is passed as an HTTP-Only cookie on successful login.

Response:

["COZY CHAT", "Kinks and jinks", "Crushampton (uncensored)", "..."]

Here's the table of possible status codes and their semantics:

Status Description
401 Unauthorized JWT cookie not found or token is invalid
200 OK Success
/profile

Request to profile is a plain GET with no data whatsoever. User's identity is established from their JWT token that is passed as an HTTP-Only cookie on successful login.

Response:

{
  "handle": "sharpvik",
  "name": "Viktor A. Rozenko Voitenko"
}

Here's the table of possible status codes and their semantics:

Status Description
401 Unauthorized JWT cookie not found or token is invalid
200 OK Success
/avatar?handle=sharpvik

Request to avatar is a plain GET with no data whatsoever. User's identity is either established from their JWT token or passed explicitly through the URL parameter (optional) called handle.

Response is an image or 404 Not Found if something went wrong.

Documentation

Overview

Package server contains all functions and methods for the main server that is the host to all API endpoints and static files for the chat.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Getter

type Getter func() (interface{}, error)

Getter should be a closure that can return to us some data to encode or an error in case of failure.

type Server

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

Server is a wrapper around http.Server that allows us to define our own convenience methods.

func NewBasicServer

func NewBasicServer() *Server

NewBasicServer returns a server with basic common-sense settings.

func NewServer

func NewServer(config configs.Server, db *sqlx.DB) (s *Server)

NewServer returns appropriate server based on the mode and configs.

func (*Server) Grace

func (s *Server) Grace(done chan bool)

Grace allows Server to shutdown gracefully based on an external done chan.

func (*Server) Serve

func (s *Server) Serve() (err error)

Serve starts the server.

func (*Server) ServeWithGrace

func (s *Server) ServeWithGrace(done chan bool)

ServeWithGrace spawns the greceful shutfown monitor thread and then calls ListenAndServe on the server.

Jump to

Keyboard shortcuts

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