feedback

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 10 Imported by: 0

README

feedback — embeddable feedback widget

feedback provides a self-contained feedback system with a Go backend and injectable JS/CSS frontend. Drop it into any HTTP service to collect user comments.

Quick start

widget, _ := feedback.New(feedback.Config{
    DB:      db,
    AppName: "myapp",
    UserIDFn: func(r *http.Request) string {
        return auth.GetClaims(r.Context()).UserID
    },
})
widget.RegisterMux(mux, "/feedback")

Endpoints

Method Path Description
POST /submit Submit a comment (JSON: {text, page_url})
GET /comments List comments as JSON (supports limit, offset)
GET /comments.html Rendered HTML list
GET /widget.js Embedded JavaScript
GET /widget.css Embedded CSS

Schema

CREATE TABLE feedback_comments (
    id         TEXT PRIMARY KEY,
    text       TEXT NOT NULL,
    page_url   TEXT,
    user_agent TEXT,
    user_id    TEXT,
    app_name   TEXT,
    created_at INTEGER NOT NULL
);

Limits

  • Request body: 32 KiB
  • Comment text: 5 000 characters
  • HTML list: 200 rows max

Exported API

Symbol Description
Widget Feedback system (schema + handlers + assets)
New(cfg) Create widget and apply schema
Config DB, AppName, UserIDFn
Comment Feedback record
Handler() http.Handler serving all endpoints
RegisterMux(mux, path) Register on a ServeMux

Documentation

Overview

Package feedback provides a self-contained feedback widget for HOROS services.

It exposes both a chi-compatible Widget.Handler and a standard Widget.RegisterMux so callers can pick whichever router they use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	ID        string  `json:"id"`
	Text      string  `json:"text"`
	PageURL   string  `json:"page_url"`
	UserAgent string  `json:"user_agent"`
	UserID    *string `json:"user_id,omitempty"`
	AppName   string  `json:"app_name"`
	CreatedAt int64   `json:"created_at"`
}

Comment represents a single feedback entry.

type Config

type Config struct {
	DB       *sql.DB
	AppName  string     // e.g. "horum" or "horostracker"
	UserIDFn UserIDFunc // nil = always anonymous
}

Config holds the settings needed to create a feedback Widget.

type UserIDFunc

type UserIDFunc func(r *http.Request) string

UserIDFunc extracts a user identifier from the HTTP request. Return "" for anonymous feedback.

type Widget

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

Widget manages the feedback system (schema, HTTP handlers, embedded assets).

func New

func New(cfg Config) (*Widget, error)

New creates a Widget and applies the database schema.

func (*Widget) Handler

func (w *Widget) Handler() http.Handler

Handler returns an http.Handler serving all feedback endpoints. The caller must strip the URL prefix before passing requests.

chi:      r.Mount("/feedback", http.StripPrefix("/feedback", w.Handler()))
ServeMux: w.RegisterMux(mux, "/feedback")

func (*Widget) RegisterMux

func (w *Widget) RegisterMux(mux *http.ServeMux, basePath string)

RegisterMux registers feedback routes directly on a standard ServeMux with explicit method+path patterns (Go 1.22+).

Jump to

Keyboard shortcuts

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