cell

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

README

cell

Cell is a module that facilitates the creation of HLHV cells. In the future, this module will contain many convenience functions to make creating a cell easier.

Creating a Cell

Compared to the previous way of creating cells, this way involves far less boilerplate. A very basic cell:

package main

import (
        "github.com/hlhv/cell"
)

func main () {
        // configure cell
        thisCell := &cell.Cell {
                Description:   "Example cell",
                MountPoint:    cell.Mount { "@", "/" },
                DataDirectory: "/var/hlhv/cells/example/",
                QueenAddress:  "localhost:2001",
                Key:           "example key",

                OnHTTP:        onHTTP,
        }

        // run cell
        thisCell.Run()
}

func onHTTP (response *cell.HTTPResponse, request *cell.HTTPRequest) {
        // passing nil writes no headers
        response.WriteHead(200, nil)
        
        // write response body
        response.WriteBody([]byte("hello, world!"))
}

Note: Running two cells within the same program will cause issues. This may be fixed in the future, however doing this is generally a bad idea and defeats the purpose of cells.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	Description   string
	MountPoint    Mount
	DataDirectory string
	QueenAddress  string
	Key           string
	RootCertPath  string

	OnHTTP  func(response *HTTPResponse, request *HTTPRequest)
	OnSetup func(cell *Cell)
	OnStop  func()
	// contains filtered or unexported fields
}

func (*Cell) RegisterDir

func (cell *Cell) RegisterDir(
	dirPath string,
	webPath string,
	active bool,
) (
	err error,
)

RegisterDir registers a directory located at the directory path on the * specific url path.

func (*Cell) RegisterFile

func (cell *Cell) RegisterFile(
	filePath string,
	webPath string,
	autoReload bool,
) (
	err error,
)

RegisterFile registers a file located at the filepath on the specific url * path.

func (*Cell) Run

func (cell *Cell) Run()

func (*Cell) SetCacheMaxAge added in v0.5.0

func (cell *Cell) SetCacheMaxAge(maxAge time.Duration)

SetCacheMaxAge sets the max age field of the cache-control header returned * when reponding to an HTTPS request with registered files.

func (*Cell) Stop added in v0.4.0

func (cell *Cell) Stop()

Stop closes the cell's leash, and all bands in it, preventing the leash from * reconnecting if it is ensured.

func (*Cell) UnregisterDir

func (cell *Cell) UnregisterDir(webPath string) (err error)

UnregisterDir finds the directory registered at the specified url path and * unregisters it, freeing it from memory

func (*Cell) UnregisterFile

func (cell *Cell) UnregisterFile(webPath string) (err error)

UnregisterFile finds the file registered at the specified url path and * unregisters it, freeing it from memory

type HTTPReqHead

type HTTPReqHead protocol.FrameHTTPReqHead

type HTTPRequest

type HTTPRequest struct {
	Head *protocol.FrameHTTPReqHead
	// contains filtered or unexported fields
}

HTTPRequest stores information about an HTTP request, and has functions for * reading it's request body.

func (*HTTPRequest) ReadBody

func (request *HTTPRequest) ReadBody() (getNext bool, data []byte, err error)

ReadBody reads a chunk of the request body. This function returns true for * getNext if the chunk was successfully read, and false if it encountered an * error or the request ended.

func (*HTTPRequest) ReadBodyFull

func (request *HTTPRequest) ReadBodyFull() (data []byte, err error)

ReadHTTPBodyFull reads all chunks of the request body, and returns the data * read as []byte.

func (*HTTPRequest) SetMaxBodySize

func (request *HTTPRequest) SetMaxBodySize(maxSize int)

SetMaxBodySize sets the maximum size for the request body to be sent to the * cell. Defaults to 8192 bytes. This function should usually be called before * reading the request body.

type HTTPResponse

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

HTTPResponse stores information about an HTTP response, and has function for * writing its response body

func (*HTTPResponse) WriteBody

func (response *HTTPResponse) WriteBody(data []byte) (err error)

WriteBody writes a chunk of the response body.

func (*HTTPResponse) WriteHead

func (response *HTTPResponse) WriteHead(
	code int,
	headers map[string][]string,
) (
	err error,
)

WriteHead writes HTTP header information. It should only be called once when * serving an HTTP response. Passing nil for headers will send no headers.

type Mount

type Mount client.Mount

Mount represents a mount pattern. It has a Host and a Path field.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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