httpserver

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 44 Imported by: 0

Documentation

Overview

Package httpserver will contain the main httpserver functionality of goshs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateQRCode

func GenerateQRCode(uri string) string

func GenerateToken

func GenerateToken() string

func GetClientIP

func GetClientIP(r *http.Request, whitelist *Whitelist) string

Types

type BreadcrumbPart struct {
	Name string
	Path string
}

BreadcrumbPart is a single segment of the path breadcrumb.

type ClipEntry

type ClipEntry struct {
	ID      int
	Content string
	Time    string
}

ClipEntry is a single clipboard entry rendered server-side.

type CustomMux

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

func NewCustomMux

func NewCustomMux() *CustomMux

NewCustomMux creates a new CustomMux instance.

func (*CustomMux) Handle

func (cm *CustomMux) Handle(pattern string, handler http.Handler)

Handle registers a new route with the CustomMux, applying all middleware in reverse order.

func (*CustomMux) HandleFunc

func (cm *CustomMux) HandleFunc(pattern string, handler http.HandlerFunc)

HandleFunc registers a new route with the CustomMux, applying all middleware in reverse order.

func (*CustomMux) ServeHTTP

func (cm *CustomMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface, allowing the CustomMux to be used as an HTTP server.

func (*CustomMux) Use

func (cm *CustomMux) Use(mw Middleware)

Use simulates the behavior of http.ServeMux.Use, allowing you to add middleware to the CustomMux.

type DownloadEntry

type DownloadEntry struct {
	DownloadURL string
	QRCode      template.URL
}

type FileItem

type FileItem struct {
	RelPath    string
	Name       string
	IsDir      bool
	Size       string // human-readable, e.g. "1.4 MB"
	SizeRaw    int64  // bytes, used for JS sorting
	LastMod    string // formatted date string
	LastModRaw int64  // unix timestamp, used for JS sorting
	Extension  string // lowercase with dot, e.g. ".go"
	QRCode     string
	Auth       bool
}

FileItem represents one row in the file listing table.

type FileServer

type FileServer struct {
	IP             string
	Port           int
	CLI            bool
	WebdavPort     int
	Webroot        string
	UploadFolder   string
	SSL            bool
	SelfSigned     bool
	LetsEncrypt    bool
	MyKey          string
	MyCert         string
	MyP12          string
	P12NoPass      bool
	User           string
	Pass           string
	CACert         string
	DropUser       string
	Version        string
	Fingerprint256 string
	Fingerprint1   string
	UploadOnly     bool
	ReadOnly       bool
	NoClipboard    bool
	NoDelete       bool
	Silent         bool
	Invisible      bool
	Embedded       bool
	Verbose        bool
	Webhook        webhook.Webhook
	Hub            *ws.Hub
	Clipboard      *clipboard.Clipboard
	Whitelist      *Whitelist
	SharedLinks    map[string]SharedLink
	Tunnel         bool
	TunnelURL      string
	Options        *options.Options
	CSRFToken      string
}

FileServer holds the fileserver information

func NewHttpServer

func NewHttpServer(opts *options.Options, hub *ws.Hub, clip *clipboard.Clipboard, wl *Whitelist, wh webhook.Webhook) *FileServer

func (*FileServer) AddCertAuth

func (files *FileServer) AddCertAuth(server *http.Server)

func (*FileServer) BasicAuthMiddleware

func (fs *FileServer) BasicAuthMiddleware(next http.Handler) http.Handler

BasicAuthMiddleware is a middleware to handle the basic auth

func (*FileServer) CreateShareHandler

func (fs *FileServer) CreateShareHandler(w http.ResponseWriter, r *http.Request)

func (*FileServer) DeleteShareHandler

func (fs *FileServer) DeleteShareHandler(w http.ResponseWriter, r *http.Request)

func (*FileServer) IPWhitelistMiddleware

func (fs *FileServer) IPWhitelistMiddleware(next http.Handler) http.Handler

IPWhitelistMiddleware checks if the request's IP is in the whitelist

func (*FileServer) InvisibleBasicAuthMiddleware

func (fs *FileServer) InvisibleBasicAuthMiddleware(next http.Handler) http.Handler

InvisibleBasicAuthMiddleware is a middleware to handle basic auth in invisible mode

func (*FileServer) PrintEmbeddedFiles

func (files *FileServer) PrintEmbeddedFiles()

func (*FileServer) ServerHeaderMiddleware

func (fs *FileServer) ServerHeaderMiddleware(next http.Handler) http.Handler

ServerHeaderMiddleware sets a custom Server header for all responses

func (*FileServer) SetupMux

func (fs *FileServer) SetupMux(mux *CustomMux, what string) string

func (*FileServer) ShareHandler

func (fs *FileServer) ShareHandler(w http.ResponseWriter, r *http.Request)

func (*FileServer) Start

func (fs *FileServer) Start(what string)

Start will start the file server

func (*FileServer) StartListener

func (fs *FileServer) StartListener(server *http.Server, what string, listener net.Listener)

type Middleware

type Middleware func(http.Handler) http.Handler
type SharedLink struct {
	FilePath        string
	IsDir           bool
	Expires         time.Time
	DownloadLimit   int
	Downloaded      int
	DownloadEntries []DownloadEntry
}

type UIData

type UIData struct {
	// Meta
	GoshsVersion string

	// Current path
	AbsPath         string
	BreadcrumbParts []BreadcrumbPart
	Subdirectory    bool
	QRCode          string
	SharedLinks     map[string]SharedLink

	// Feature flags (controls which tabs/buttons appear)
	ReadOnly    bool
	UploadOnly  bool
	NoClipboard bool
	NoDelete    bool
	CLI         bool
	Embedded    bool

	// File listing
	Items []FileItem

	// Embedded files
	EmbeddedItems []FileItem

	// Clipboard entries (pre-loaded from server state)
	Clipboard []ClipEntry

	// CSRF token embedded into the page for JS to read
	CSRFToken string
}

UIData is the struct passed to index.html on every page render. Map your existing FileServer fields onto this when calling renderIndex.

type Whitelist

type Whitelist struct {
	Networks       []*net.IPNet
	TrustedProxies []*net.IPNet
	Enabled        bool
}

func NewIPWhitelist

func NewIPWhitelist(cidrs string, enabled bool, trustedProxies string) (*Whitelist, error)

func (*Whitelist) IsAllowed

func (w *Whitelist) IsAllowed(ipStr string) bool

func (*Whitelist) IsTrustedProxy

func (w *Whitelist) IsTrustedProxy(ipStr string) bool

Jump to

Keyboard shortcuts

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