package
0.0.0-20220616105647-5b64ff3010ba
Repository: https://github.com/sharpvik/mess.git
Documentation: pkg.go.dev

# 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:

StatusDescription
500 Internal server errorUsually due to failed password hashing
409 ConflictUsername is taken
200 OKSuccess

/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:

StatusDescription
404 Not foundUsername does not exist in the database
401 UnauthorizedInvalid password
500 Internal server errorFailed to generate a JWT token
200 OKSuccess

/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:

StatusDescription
401 UnauthorizedJWT cookie not found or token is invalid
200 OKSuccess

/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:

StatusDescription
401 UnauthorizedJWT cookie not found or token is invalid
200 OKSuccess

/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.

# Functions

NewBasicServer returns a server with basic common-sense settings.
NewServer returns appropriate server based on the mode and configs.

# Structs

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

# Type aliases

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