CodeSampleX

샘플

github.com/go-sql-driver/mysql v1.7.1: NewConfig

검증된 샘플 — golang github.com/go-sql-driver/mysql v1.7.1: NewConfig. go 1.26 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: mysql.NewConfig returns a…

sha256:4e027662d3f258c3788f1e5932f4ca92345bfed8df2039359c22722bfe374984

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 go

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify github.com/go-sql-driver/mysql.NewConfig in pkg:golang/github.com/go-sql-driver/mysql@v1.7.1
패키지
심벌
  • github.com/go-sql-driver/mysql.NewConfig
생성일
2026-08-26T01:34:32Z

컨트랙트

  1. mysql.NewConfig returns a non-nil *mysql.Config initialized with default collation utf8mb4_general_ci, UTC location, AllowNativePasswords true, and CheckConnLiveness true
  2. mysql.NewConfig sets default MaxAllowedPacket to 67108864 (64MB)
  3. mysql.NewConfig creates an empty-credential Config that formats to a valid base DSN and can be customized with User, Passwd, Net, Addr, and DBName
  4. mysql.Config.Clone returns an independent deep copy of the configuration where modifying cloned properties and Params map does not mutate the original
  5. mysql.Config.FormatDSN formats extended connection options such as ParseTime and Timeout which can be round-trip parsed by mysql.ParseDSN

파일

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
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.NewConfig 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.NewConfig
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.
csx.json
{"case":{"caseId":"case:sha256:a1929eaf54ba8db2bfb8ff910feba49828db573e969484b95d74f261f07e61f0","contract":["mysql.NewConfig returns a non-nil *mysql.Config initialized with default collation utf8mb4_general_ci, UTC location, AllowNativePasswords true, and CheckConnLiveness true","mysql.NewConfig sets default MaxAllowedPacket to 67108864 (64MB)","mysql.NewConfig creates an empty-credential Config that formats to a valid base DSN and can be customized with User, Passwd, Net, Addr, and DBName","mysql.Config.Clone returns an independent deep copy of the configuration where modifying cloned properties and Params map does not mutate the original","mysql.Config.FormatDSN formats extended connection options such as ParseTime and Timeout which can be round-trip parsed by mysql.ParseDSN"],"goal":"verify github.com/go-sql-driver/mysql.NewConfig 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.NewConfig"]},"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.NewConfig"],"verifierAdapter":"golang@1"}
go.mod
module sample-mysql-newconfig

go 1.26.6

require github.com/go-sql-driver/mysql v1.7.1
go.sum
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=
main.go
package main

import (
	"fmt"
	"time"

	"github.com/go-sql-driver/mysql"
)

func main() {
	// Initialize default configuration
	cfg := mysql.NewConfig()

	// Inspect default properties configured by NewConfig
	fmt.Printf("Default collation: %s\n", cfg.Collation)
	fmt.Printf("Default location: %v\n", cfg.Loc)
	fmt.Printf("Native passwords allowed: %t\n", cfg.AllowNativePasswords)
	fmt.Printf("Connection liveness checked: %t\n", cfg.CheckConnLiveness)
	fmt.Printf("Max allowed packet: %d\n", cfg.MaxAllowedPacket)

	// Customize connection parameters
	cfg.User = "appuser"
	cfg.Passwd = "secret"
	cfg.Net = "tcp"
	cfg.Addr = "127.0.0.1:3306"
	cfg.DBName = "appdb"
	cfg.ParseTime = true
	cfg.Timeout = 5 * time.Second

	// Format DSN string
	dsn := cfg.FormatDSN()
	fmt.Printf("Formatted DSN: %s\n", dsn)

	// Clone configuration to create an independent copy
	clonedCfg := cfg.Clone()
	clonedCfg.DBName = "testdb"
	fmt.Printf("Original DB: %s, Cloned DB: %s\n", cfg.DBName, clonedCfg.DBName)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/go-sql-driver/mysql.NewConfig 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.NewConfig"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"time"

	"github.com/go-sql-driver/mysql"
)

func main() {
	// Assertion 1: mysql.NewConfig returns a non-nil *mysql.Config initialized with default collation utf8mb4_general_ci, UTC location, AllowNativePasswords true, and CheckConnLiveness true
	{
		cfg := mysql.NewConfig()
		if cfg == nil {
			fmt.Fprintf(os.Stderr, "Assertion 1 failed: mysql.NewConfig returned nil\n")
			os.Exit(1)
		}
		if cfg.Collation != "utf8mb4_general_ci" {
			fmt.Fprintf(os.Stderr, "Assertion 1 failed: expected Collation 'utf8mb4_general_ci', got %q\n", cfg.Collation)
			os.Exit(1)
		}
		if cfg.Loc != time.UTC {
			fmt.Fprintf(os.Stderr, "Assertion 1 failed: expected Loc UTC, got %v\n", cfg.Loc)
			os.Exit(1)
		}
		if !cfg.AllowNativePasswords {
			fmt.Fprintf(os.Stderr, "Assertion 1 failed: expected AllowNativePasswords to be true\n")
			os.Exit(1)
		}
		if !cfg.CheckConnLiveness {
			fmt.Fprintf(os.Stderr, "Assertion 1 failed: expected CheckConnLiveness to be true\n")
			os.Exit(1)
		}
	}

	// Assertion 2: mysql.NewConfig sets default MaxAllowedPacket to 67108864 (64MB)
	{
		cfg := mysql.NewConfig()
		if cfg.MaxAllowedPacket != 67108864 {
			fmt.Fprintf(os.Stderr, "Assertion 2 failed: expected MaxAllowedPacket 67108864, got %d\n", cfg.MaxAllowedPacket)
			os.Exit(1)
		}
	}

	// Assertion 3: mysql.NewConfig creates an empty-credential Config that formats to a valid base DSN and can be customized with User, Passwd, Net, Addr, and DBName
	{
		cfg := mysql.NewConfig()
		cfg.User = "dbuser"
		cfg.Passwd = "dbpass"
		cfg.Net = "tcp"
		cfg.Addr = "127.0.0.1:3306"
		cfg.DBName = "testdb"

		expectedDSN := "dbuser:dbpass@tcp(127.0.0.1:3306)/testdb"
		if dsn := cfg.FormatDSN(); dsn != expectedDSN {
			fmt.Fprintf(os.Stderr, "Assertion 3 failed: expected DSN %q, got %q\n", expectedDSN, dsn)
			os.Exit(1)
		}
	}

	// Assertion 4: mysql.Config.Clone returns an independent deep copy of the configuration where modifying cloned properties and Params map does not mutate the original
	{
		orig := mysql.NewConfig()
		orig.User = "root"
		orig.DBName = "production"
		orig.Params = map[string]string{
			"charset": "utf8mb4",
		}

		cloned := orig.Clone()
		if cloned.User != "root" || cloned.DBName != "production" {
			fmt.Fprintf(os.Stderr, "Assertion 4 failed: clone field mismatch\n")
			os.Exit(1)
		}

		cloned.DBName = "staging"
		cloned.Params["charset"] = "latin1"
		cloned.Params["custom"] = "value"

		if orig.DBName != "production" {
			fmt.Fprintf(os.Stderr, "Assertion 4 failed: mutating clone modified original DBName\n")
			os.Exit(1)
		}
		if orig.Params["charset"] != "utf8mb4" || len(orig.Params) != 1 {
			fmt.Fprintf(os.Stderr, "Assertion 4 failed: mutating clone params modified original params\n")
			os.Exit(1)
		}
	}

	// Assertion 5: mysql.Config.FormatDSN formats extended connection options such as ParseTime and Timeout which can be round-trip parsed by mysql.ParseDSN
	{
		cfg := mysql.NewConfig()
		cfg.User = "app"
		cfg.Passwd = "secret"
		cfg.Net = "tcp"
		cfg.Addr = "localhost:3306"
		cfg.DBName = "appdb"
		cfg.ParseTime = true
		cfg.Timeout = 10 * time.Second

		dsn := cfg.FormatDSN()
		parsed, err := mysql.ParseDSN(dsn)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Assertion 5 failed: mysql.ParseDSN failed on formatted DSN: %v\n", err)
			os.Exit(1)
		}
		if parsed.User != cfg.User || parsed.Passwd != cfg.Passwd || parsed.Net != cfg.Net || parsed.Addr != cfg.Addr || parsed.DBName != cfg.DBName {
			fmt.Fprintf(os.Stderr, "Assertion 5 failed: parsed credentials/target mismatch\n")
			os.Exit(1)
		}
		if !parsed.ParseTime {
			fmt.Fprintf(os.Stderr, "Assertion 5 failed: expected ParseTime true in parsed config\n")
			os.Exit(1)
		}
		if parsed.Timeout != 10*time.Second {
			fmt.Fprintf(os.Stderr, "Assertion 5 failed: expected Timeout 10s, got %v\n", parsed.Timeout)
			os.Exit(1)
		}
	}

	fmt.Println("All mysql.NewConfig contract assertions passed.")
}

오리진 시더

익명