Help us shape the future of Go! Take the 2026 Go Developer Survey

demo

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package demo is a small API for testing DriftGate end to end. Version "v1" is the baseline; "v2" plants drift: a string ID becomes a number, the date format changes, a key appears, a header is added and creating a FAQ entry also writes a log row. Some requests change data, reading a news item among them; one returns personal data, and tokens and cookies are new each time.

The data lives in memory, or in a MySQL/MariaDB database (NewSQL), so the state components of DriftGate can be tested against it.

Index

Constants

View Source
const (
	ChangeUpload = "upload" // the import reads values as whole numbers
	ChangeJob    = "job"    // the queued import job fails
	ChangeExport = "export" // the export renames a column
	ChangeLimit  = "limit"  // the rate limit is 59 per minute instead of 60
)

Planted changes of the upload, queue, export and rate-limit endpoints, switched on with Plant while the server runs.

View Source
const AdminToken = "demo-admin-token"

AdminToken is the token the demo accepts for its one identity.

View Source
const RateLimit = 60

RateLimit is the number of likes a client may send per minute.

Variables

View Source
var Schema = []string{
	"CREATE TABLE news (id INT PRIMARY KEY, views INT NOT NULL)",
	"INSERT INTO news VALUES (11, 41), (12, 9)",
	"CREATE TABLE faq (id INT AUTO_INCREMENT PRIMARY KEY, created_at DATETIME NOT NULL)",
	"CREATE TABLE faq_log (id INT AUTO_INCREMENT PRIMARY KEY, faq_id INT NOT NULL)",
}

Schema creates the demo tables with their initial data in a MySQL or MariaDB database.

Functions

This section is empty.

Types

type Server

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

Server is the demo API.

func New

func New(version string) *Server

New returns a demo server of the given version that keeps its data in memory.

func NewSQL

func NewSQL(version string, db *sql.DB) *Server

NewSQL returns a demo server whose data is in db (see Schema).

func (*Server) Plant

func (s *Server) Plant(change string, on bool)

Plant switches a planted change (Change*) on or off. Planted changes survive /admin/reset, which restores data only.

func (*Server) Reset

func (s *Server) Reset()

Reset restores the initial data.

func (*Server) ServeHTTP

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

ServeHTTP implements the API.

func (*Server) SetVersion

func (s *Server) SetVersion(v string)

SetVersion switches between "v1" and "v2" while running.

Jump to

Keyboard shortcuts

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