logapi

package module
v0.0.0-...-9e74ca5 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: MPL-2.0 Imports: 10 Imported by: 0

README

logapi

An API to store, retrieve, and automatically archive log files.

/mnt/storage/blobs/api_log/2025-07/1234.json
/mnt/storage/blobs/api_log/2025-07.tar.zst#2025-07/1234.json

Table of Contents

  • Usage
  • Build
  • Deploy
  • API Keys

Usage

POST /api/logs
curl -X POST "${LOG_BASEURL}/api/logs" \
    --user "${LOG_USER}:${LOG_TOKEN}" \
    -H "X-File-Date: 2025-07" \
    -H "X-File-Name: 1234.json" \
    -H "Content-Type: application/json" \
    --data-binary '{ "foo": "bar" }'
GET /api/logs/<user>
curl "${LOG_BASEURL}/api/logs/${LOG_USER}" \
    --user "${LOG_USER}:${LOG_TOKEN}"
{ "results": ["2025-07"] }
GET /api/logs/<user>/<YYYY-MM>
curl "${LOG_BASEURL}/api/logs/${LOG_USER}/2025-07" \
    --user "${LOG_USER}:${LOG_TOKEN}"
{ "results": ["1234.json"] }
GET /api/logs/<user>/<YYYY-MM>/<filename>
curl "${LOG_BASEURL}/api/logs/${LOG_USER}/2025-07/1234.json" \
    --user "${LOG_USER}:${LOG_TOKEN}"

Build

GOOS=linux GOARCH=amd64 GOAMD=v2 go build -o ./logapid-linux-x86_64 ./cmd/logapid/

scp -rp ./logapid-linux-x86_64 server:~/bin/logapid

Deploy

webi serviceman
serviceman add --name logapid -- \
    logapid --tsv ~/.config/logapid/credentials.tsv --storage /mnt/storage/blobs --port 8080

Set API Keys

go run ./cmd/csvpass/ set --algorithm=plain 'api_log'
go run ./cmd/csvpass/ set --algorithm=pbkdf2,4096,16,SHA-256 'api_log'
go run ./cmd/csvpass/ set --algorithm=bcrypt,10 'webhooks_log'

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicAuthVerifier

type BasicAuthVerifier interface {
	Verify(string, string) bool
}

type JSONError

type JSONError struct {
	Error  string `json:"error"`
	Code   string `json:"code"`
	Detail string `json:"detail"`
}

JSONError represents an API error response

type Request

type Request struct {
	Date string `json:"date"`
	Name string `json:"name"`
	Path string `json:"path"`
}

Request represents the POST /api/logs JSON body

type Server

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

Server holds application state

func New

func New(auth BasicAuthVerifier, storage string, compress string) (*Server, error)

New initializes the server

func (*Server) CompressAll

func (s *Server) CompressAll(now time.Time, stale time.Duration) ([]string, error)

func (*Server) GetFile

func (s *Server) GetFile(w http.ResponseWriter, r *http.Request)

func (*Server) ListFiles

func (s *Server) ListFiles(w http.ResponseWriter, r *http.Request)

func (*Server) ListMonths

func (s *Server) ListMonths(w http.ResponseWriter, r *http.Request)

func (*Server) UploadLog

func (s *Server) UploadLog(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis
cmd
csvpass command
logapid command

Jump to

Keyboard shortcuts

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