Sample
github.com/go-sql-driver/mysql v1.7.1: ParseDSN
Verified sample for golang github.com/go-sql-driver/mysql v1.7.1: ParseDSN. The contract ran on go 1.26 · linux alpine/x64 · docker and passed.
sha256:dd0feeffababeda429e4851604f41df0449ce3ba155697d32c0f388c17013e70
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 2
- Signing keys that built it
- 1
Declared environment
linux 24 · ubuntu · glibc 2.39 x64 go
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-08-26 |
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-09-07 |
Case
HOW- Goal
- verify github.com/go-sql-driver/mysql.ParseDSN in pkg:golang/github.com/go-sql-driver/mysql@v1.7.1
- Symbols
-
- github.com/go-sql-driver/mysql.ParseDSN
- Created
- 2026-08-26T01:39:37Z
Contract
- mysql.ParseDSN parses username, password, network protocol, address, and database name from standard DSN
- mysql.ParseDSN parses query parameters and configures driver options including ParseTime and Timeout
- mysql.ParseDSN parses minimal DSN string containing only database name
- mysql.ParseDSN parses extended configuration options including InterpolateParams and Collation
- mysql.ParseDSN returns error for invalid DSN strings
- Config.FormatDSN formats parsed Config struct back to a valid DSN string
Files
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Source
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify github.com/go-sql-driver/mysql.ParseDSN in pkg:golang/github.com/go-sql-driver/mysql@v1.7.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/go-sql-driver/mysql@v1.7.1
Demonstrate these symbols/APIs:
- github.com/go-sql-driver/mysql.ParseDSN
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:515aae73e1969e9b35bc384846b76a620f599455c066d33b0275281c7a70e3f7","contract":["mysql.ParseDSN parses username, password, network protocol, address, and database name from standard DSN","mysql.ParseDSN parses query parameters and configures driver options including ParseTime and Timeout","mysql.ParseDSN parses minimal DSN string containing only database name","mysql.ParseDSN parses extended configuration options including InterpolateParams and Collation","mysql.ParseDSN returns error for invalid DSN strings","Config.FormatDSN formats parsed Config struct back to a valid DSN string"],"goal":"verify github.com/go-sql-driver/mysql.ParseDSN in pkg:golang/github.com/go-sql-driver/mysql@v1.7.1","kind":"HOW","packages":["pkg:golang/github.com/go-sql-driver/mysql@v1.7.1"],"schemaVersion":1,"symbols":["github.com/go-sql-driver/mysql.ParseDSN"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/go-sql-driver/mysql@v1.7.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/go-sql-driver/mysql@v1.7.1","symbols":["github.com/go-sql-driver/mysql.ParseDSN"],"verifierAdapter":"golang@1"}
module sample-mysql-parse-dsn
go 1.26.6
require github.com/go-sql-driver/mysql v1.7.1
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
package main
import (
"fmt"
"log"
"github.com/go-sql-driver/mysql"
)
func main() {
// Parse a standard MySQL Data Source Name (DSN)
dsn := "alice:secret123@tcp(127.0.0.1:3306)/sampledb?parseTime=true&charset=utf8mb4"
cfg, err := mysql.ParseDSN(dsn)
if err != nil {
log.Fatalf("failed to parse DSN: %v", err)
}
// Inspect parsed configuration fields
fmt.Printf("User: %s\n", cfg.User)
fmt.Printf("Network: %s\n", cfg.Net)
fmt.Printf("Address: %s\n", cfg.Addr)
fmt.Printf("DBName: %s\n", cfg.DBName)
fmt.Printf("ParseTime: %t\n", cfg.ParseTime)
fmt.Printf("Charset: %s\n", cfg.Params["charset"])
// Format Config back into a DSN connection string
formattedDSN := cfg.FormatDSN()
fmt.Printf("Formatted DSN: %s\n", formattedDSN)
}
{
"schemaVersion": 1,
"goal": "verify github.com/go-sql-driver/mysql.ParseDSN in pkg:golang/github.com/go-sql-driver/mysql@v1.7.1",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/go-sql-driver/mysql@v1.7.1"
],
"symbols": [
"github.com/go-sql-driver/mysql.ParseDSN"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
package main
import (
"fmt"
"os"
"time"
"github.com/go-sql-driver/mysql"
)
func main() {
// Assertion 1: mysql.ParseDSN parses username, password, network protocol, address, and database name from standard DSN
{
dsn := "alice:secret123@tcp(127.0.0.1:3306)/sampledb"
cfg, err := mysql.ParseDSN(dsn)
if err != nil {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: unexpected error parsing DSN: %v\n", err)
os.Exit(1)
}
if cfg.User != "alice" {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: expected User 'alice', got %q\n", cfg.User)
os.Exit(1)
}
if cfg.Passwd != "secret123" {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: expected Passwd 'secret123', got %q\n", cfg.Passwd)
os.Exit(1)
}
if cfg.Net != "tcp" {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: expected Net 'tcp', got %q\n", cfg.Net)
os.Exit(1)
}
if cfg.Addr != "127.0.0.1:3306" {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: expected Addr '127.0.0.1:3306', got %q\n", cfg.Addr)
os.Exit(1)
}
if cfg.DBName != "sampledb" {
fmt.Fprintf(os.Stderr, "Assertion 1 failed: expected DBName 'sampledb', got %q\n", cfg.DBName)
os.Exit(1)
}
}
// Assertion 2: mysql.ParseDSN parses query parameters and configures driver options including ParseTime and Timeout
{
dsn := "alice:secret123@tcp(127.0.0.1:3306)/sampledb?parseTime=true&charset=utf8mb4&timeout=5s"
cfg, err := mysql.ParseDSN(dsn)
if err != nil {
fmt.Fprintf(os.Stderr, "Assertion 2 failed: unexpected error: %v\n", err)
os.Exit(1)
}
if !cfg.ParseTime {
fmt.Fprintf(os.Stderr, "Assertion 2 failed: expected ParseTime true, got false\n")
os.Exit(1)
}
if cfg.Params["charset"] != "utf8mb4" {
fmt.Fprintf(os.Stderr, "Assertion 2 failed: expected charset 'utf8mb4', got %q\n", cfg.Params["charset"])
os.Exit(1)
}
if cfg.Timeout != 5*time.Second {
fmt.Fprintf(os.Stderr, "Assertion 2 failed: expected Timeout 5s, got %v\n", cfg.Timeout)
os.Exit(1)
}
}
// Assertion 3: mysql.ParseDSN parses minimal DSN string containing only database name
{
dsn := "/testdb"
cfg, err := mysql.ParseDSN(dsn)
if err != nil {
fmt.Fprintf(os.Stderr, "Assertion 3 failed: unexpected error: %v\n", err)
os.Exit(1)
}
if cfg.DBName != "testdb" {
fmt.Fprintf(os.Stderr, "Assertion 3 failed: expected DBName 'testdb', got %q\n", cfg.DBName)
os.Exit(1)
}
if cfg.User != "" {
fmt.Fprintf(os.Stderr, "Assertion 3 failed: expected empty User, got %q\n", cfg.User)
os.Exit(1)
}
}
// Assertion 4: mysql.ParseDSN parses extended configuration options including InterpolateParams and Collation
{
dsn := "alice:secret123@tcp(127.0.0.1:3306)/sampledb?interpolateParams=true&collation=utf8mb4_general_ci"
cfg, err := mysql.ParseDSN(dsn)
if err != nil {
fmt.Fprintf(os.Stderr, "Assertion 4 failed: unexpected error: %v\n", err)
os.Exit(1)
}
if !cfg.InterpolateParams {
fmt.Fprintf(os.Stderr, "Assertion 4 failed: expected InterpolateParams true, got false\n")
os.Exit(1)
}
if cfg.Collation != "utf8mb4_general_ci" {
fmt.Fprintf(os.Stderr, "Assertion 4 failed: expected Collation 'utf8mb4_general_ci', got %q\n", cfg.Collation)
os.Exit(1)
}
}
// Assertion 5: mysql.ParseDSN returns error for invalid DSN strings
{
invalidDSN := "alice:secret@tcp(127.0.0.1:3306)/sampledb?parseTime=not_a_boolean"
_, err := mysql.ParseDSN(invalidDSN)
if err == nil {
fmt.Fprintf(os.Stderr, "Assertion 5 failed: expected error for invalid parseTime parameter, got nil\n")
os.Exit(1)
}
}
// Assertion 6: Config.FormatDSN formats parsed Config struct back to a valid DSN string
{
originalDSN := "alice:secret123@tcp(127.0.0.1:3306)/sampledb?charset=utf8mb4&parseTime=true"
cfg, err := mysql.ParseDSN(originalDSN)
if err != nil {
fmt.Fprintf(os.Stderr, "Assertion 6 failed: ParseDSN failed: %v\n", err)
os.Exit(1)
}
formatted := cfg.FormatDSN()
cfg2, err := mysql.ParseDSN(formatted)
if err != nil {
fmt.Fprintf(os.Stderr, "Assertion 6 failed: ParseDSN on formatted string %q failed: %v\n", formatted, err)
os.Exit(1)
}
if cfg2.User != cfg.User || cfg2.DBName != cfg.DBName || cfg2.Net != cfg.Net || cfg2.Addr != cfg.Addr || cfg2.ParseTime != cfg.ParseTime {
fmt.Fprintf(os.Stderr, "Assertion 6 failed: parsed Config mismatch between original and formatted DSN\n")
os.Exit(1)
}
}
fmt.Println("All ParseDSN contract assertions passed.")
}
Origin Seeder
anonymous