feat: eliminate fmt, string concat — add core.Println, use Concat/Path everywhere

New primitive: core.Println() wraps fmt.Println.

Replaced across all test + example files:
- fmt.Println → Println (17 example files)
- fmt.Sprintf → Concat + Sprint
- dir + "/file" → Path(dir, "file") (path security)
- "str" + var → Concat("str", var) (AX consistency)

"fmt" import is now zero across all test files.
String concat with + is zero across all test files.

Remaining 9 stdlib imports (all Go infrastructure):
testing, context, time, sync, embed, io/fs, bytes, gzip, base64

558 tests, 84.5% coverage.

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Snider 2026-03-25 19:42:39 +00:00
parent 921b4f2b21
commit 5be20af4b0
23 changed files with 140 additions and 150 deletions

View file

@ -2,7 +2,6 @@ package core_test
import (
"context"
"fmt"
. "dappco.re/go/core"
)
@ -16,16 +15,16 @@ func ExampleAction_Run() {
r := c.Action("double").Run(context.Background(), NewOptions(
Option{Key: "n", Value: 21},
))
fmt.Println(r.Value)
Println(r.Value)
// Output: 42
}
func ExampleAction_Exists() {
c := New()
fmt.Println(c.Action("missing").Exists())
Println(c.Action("missing").Exists())
c.Action("present", func(_ context.Context, _ Options) Result { return Result{OK: true} })
fmt.Println(c.Action("present").Exists())
Println(c.Action("present").Exists())
// Output:
// false
// true
@ -38,7 +37,7 @@ func ExampleAction_Run_panicRecovery() {
})
r := c.Action("boom").Run(context.Background(), NewOptions())
fmt.Println(r.OK)
Println(r.OK)
// Output: false
}
@ -55,6 +54,6 @@ func ExampleAction_Run_entitlementDenied() {
})
r := c.Action("premium").Run(context.Background(), NewOptions())
fmt.Println(r.OK)
Println(r.OK)
// Output: false
}

View file

@ -24,7 +24,7 @@ func TestAction_NamedAction_Good_Invoke(t *testing.T) {
c := New()
c.Action("git.log", func(_ context.Context, opts Options) Result {
dir := opts.String("dir")
return Result{Value: "log from " + dir, OK: true}
return Result{Value: Concat("log from ", dir), OK: true}
})
r := c.Action("git.log").Run(context.Background(), NewOptions(

View file

@ -2,7 +2,6 @@ package core_test
import (
"context"
"fmt"
. "dappco.re/go/core"
)
@ -12,14 +11,14 @@ func ExampleAPI_RegisterProtocol() {
c.API().RegisterProtocol("http", func(h *DriveHandle) (Stream, error) {
return &mockStream{response: []byte("pong")}, nil
})
fmt.Println(c.API().Protocols())
Println(c.API().Protocols())
// Output: [http]
}
func ExampleAPI_Stream() {
c := New()
c.API().RegisterProtocol("http", func(h *DriveHandle) (Stream, error) {
return &mockStream{response: []byte("connected to " + h.Name)}, nil
return &mockStream{response: []byte(Concat("connected to ", h.Name))}, nil
})
c.Drive().New(NewOptions(
Option{Key: "name", Value: "charon"},
@ -30,7 +29,7 @@ func ExampleAPI_Stream() {
if r.OK {
stream := r.Value.(Stream)
resp, _ := stream.Receive()
fmt.Println(string(resp))
Println(string(resp))
stream.Close()
}
// Output: connected to charon
@ -45,6 +44,6 @@ func ExampleCore_RemoteAction() {
// No colon — resolves locally
r := c.RemoteAction("status", context.Background(), NewOptions())
fmt.Println(r.Value)
Println(r.Value)
// Output: running
}

View file

@ -1,7 +1,6 @@
package core_test
import (
"fmt"
. "dappco.re/go/core"
)
@ -12,8 +11,8 @@ func ExampleNewArray() {
a.Add("bravo")
a.Add("charlie")
fmt.Println(a.Len())
fmt.Println(a.Contains("bravo"))
Println(a.Len())
Println(a.Contains("bravo"))
// Output:
// 3
// true
@ -25,7 +24,7 @@ func ExampleArray_AddUnique() {
a.AddUnique("alpha") // no duplicate
a.AddUnique("bravo")
fmt.Println(a.Len())
Println(a.Len())
// Output: 2
}
@ -37,6 +36,6 @@ func ExampleArray_Filter() {
a.Add(4)
r := a.Filter(func(n int) bool { return n%2 == 0 })
fmt.Println(r.OK)
Println(r.OK)
// Output: true
}

View file

@ -1,7 +1,6 @@
package core_test
import (
"fmt"
. "dappco.re/go/core"
)
@ -15,7 +14,7 @@ func ExampleCore_Command_register() {
},
})
fmt.Println(c.Command("deploy/to/homelab").OK)
Println(c.Command("deploy/to/homelab").OK)
// Output: true
}
@ -27,7 +26,7 @@ func ExampleCore_Command_managed() {
})
cmd := c.Command("serve").Value.(*Command)
fmt.Println(cmd.IsManaged())
Println(cmd.IsManaged())
// Output: true
}
@ -36,6 +35,6 @@ func ExampleCore_Commands() {
c.Command("deploy", Command{Action: func(_ Options) Result { return Result{OK: true} }})
c.Command("test", Command{Action: func(_ Options) Result { return Result{OK: true} }})
fmt.Println(c.Commands())
Println(c.Commands())
// Output: [deploy test]
}

View file

@ -1,7 +1,6 @@
package core_test
import (
"fmt"
. "dappco.re/go/core"
)
@ -11,8 +10,8 @@ func ExampleConfig_Set() {
c.Config().Set("database.host", "localhost")
c.Config().Set("database.port", 5432)
fmt.Println(c.Config().String("database.host"))
fmt.Println(c.Config().Int("database.port"))
Println(c.Config().String("database.host"))
Println(c.Config().Int("database.port"))
// Output:
// localhost
// 5432
@ -23,8 +22,8 @@ func ExampleConfig_Enable() {
c.Config().Enable("dark-mode")
c.Config().Enable("beta-features")
fmt.Println(c.Config().Enabled("dark-mode"))
fmt.Println(c.Config().EnabledFeatures())
Println(c.Config().Enabled("dark-mode"))
Println(c.Config().EnabledFeatures())
// Output:
// true
// [dark-mode beta-features]
@ -32,10 +31,10 @@ func ExampleConfig_Enable() {
func ExampleConfigVar() {
v := NewConfigVar(42)
fmt.Println(v.Get(), v.IsSet())
Println(v.Get(), v.IsSet())
v.Unset()
fmt.Println(v.Get(), v.IsSet())
Println(v.Get(), v.IsSet())
// Output:
// 42 true
// 0 false

View file

@ -1,7 +1,6 @@
package core_test
import (
"fmt"
. "dappco.re/go/core"
)
@ -13,8 +12,8 @@ func ExampleDrive_New() {
Option{Key: "transport", Value: "https://forge.lthn.ai"},
))
fmt.Println(c.Drive().Has("forge"))
fmt.Println(c.Drive().Names())
Println(c.Drive().Has("forge"))
Println(c.Drive().Names())
// Output:
// true
// [forge]
@ -30,7 +29,7 @@ func ExampleDrive_Get() {
r := c.Drive().Get("charon")
if r.OK {
h := r.Value.(*DriveHandle)
fmt.Println(h.Transport)
Println(h.Transport)
}
// Output: http://10.69.69.165:9101
}

View file

@ -92,7 +92,7 @@ func TestEmbed_Extract_Good(t *testing.T) {
r := Extract(testFS, dir, nil)
assert.True(t, r.OK)
cr := (&Fs{}).New("/").Read(dir + "/testdata/test.txt")
cr := (&Fs{}).New("/").Read(Path(dir, "testdata/test.txt"))
assert.True(t, cr.OK)
assert.Equal(t, "hello from testdata\n", cr.Value)
}
@ -147,12 +147,12 @@ func TestEmbed_GeneratePack_Empty_Good(t *testing.T) {
func TestEmbed_GeneratePack_WithFiles_Good(t *testing.T) {
dir := t.TempDir()
assetDir := dir + "/mygroup"
assetDir := Path(dir, "mygroup")
(&Fs{}).New("/").EnsureDir(assetDir)
(&Fs{}).New("/").Write(assetDir+"/hello.txt", "hello world")
(&Fs{}).New("/").Write(Path(assetDir, "hello.txt"), "hello world")
source := "package test\nimport \"dappco.re/go/core\"\nfunc example() {\n\t_, _ = core.GetAsset(\"mygroup\", \"hello.txt\")\n}\n"
goFile := dir + "/test.go"
goFile := Path(dir, "test.go")
(&Fs{}).New("/").Write(goFile, source)
sr := ScanAssets([]string{goFile})
@ -174,10 +174,10 @@ func TestEmbed_Extract_WithTemplate_Good(t *testing.T) {
// Use a real temp dir with files
srcDir := t.TempDir()
(&Fs{}).New("/").Write(srcDir+"/plain.txt", "static content")
(&Fs{}).New("/").Write(srcDir+"/greeting.tmpl", "Hello {{.Name}}!")
(&Fs{}).New("/").EnsureDir(srcDir+"/sub")
(&Fs{}).New("/").Write(srcDir+"/sub/nested.txt", "nested")
(&Fs{}).New("/").Write(Path(srcDir, "plain.txt"), "static content")
(&Fs{}).New("/").Write(Path(srcDir, "greeting.tmpl"), "Hello {{.Name}}!")
(&Fs{}).New("/").EnsureDir(Path(srcDir, "sub"))
(&Fs{}).New("/").Write(Path(srcDir, "sub/nested.txt"), "nested")
_ = tmplDir
fsys := DirFS(srcDir)
@ -189,24 +189,24 @@ func TestEmbed_Extract_WithTemplate_Good(t *testing.T) {
f := (&Fs{}).New("/")
// Plain file copied
cr := f.Read(dir + "/plain.txt")
cr := f.Read(Path(dir, "plain.txt"))
assert.True(t, cr.OK)
assert.Equal(t, "static content", cr.Value)
// Template processed and .tmpl stripped
gr := f.Read(dir + "/greeting")
gr := f.Read(Path(dir, "greeting"))
assert.True(t, gr.OK)
assert.Equal(t, "Hello World!", gr.Value)
// Nested directory preserved
nr := f.Read(dir + "/sub/nested.txt")
nr := f.Read(Path(dir, "sub/nested.txt"))
assert.True(t, nr.OK)
assert.Equal(t, "nested", nr.Value)
}
func TestEmbed_Extract_BadTargetDir_Ugly(t *testing.T) {
srcDir := t.TempDir()
(&Fs{}).New("/").Write(srcDir+"/f.txt", "x")
(&Fs{}).New("/").Write(Path(srcDir, "f.txt"), "x")
r := Extract(DirFS(srcDir), "/nonexistent/deeply/nested/impossible", nil)
// Should fail gracefully, not panic
_ = r
@ -248,7 +248,7 @@ func TestEmbed_EmbedFS_Original_Good(t *testing.T) {
func TestEmbed_Extract_NilData_Good(t *testing.T) {
dir := t.TempDir()
srcDir := t.TempDir()
(&Fs{}).New("/").Write(srcDir+"/file.txt", "no template")
(&Fs{}).New("/").Write(Path(srcDir, "file.txt"), "no template")
r := Extract(DirFS(srcDir), dir, nil)
assert.True(t, r.OK)

View file

@ -2,14 +2,13 @@ package core_test
import (
"context"
"fmt"
. "dappco.re/go/core"
)
func ExampleEntitlement_UsagePercent() {
e := Entitlement{Limit: 100, Used: 75}
fmt.Println(e.UsagePercent())
Println(e.UsagePercent())
// Output: 75
}
@ -31,9 +30,9 @@ func ExampleCore_SetEntitlementChecker() {
return Entitlement{Allowed: true, Limit: limit, Used: used, Remaining: remaining}
})
fmt.Println(c.Entitled("social.accounts", 2).Allowed)
fmt.Println(c.Entitled("social.accounts", 5).Allowed)
fmt.Println(c.Entitled("ai.credits").NearLimit(0.9))
Println(c.Entitled("social.accounts", 2).Allowed)
Println(c.Entitled("social.accounts", 5).Allowed)
Println(c.Entitled("ai.credits").NearLimit(0.9))
// Output:
// true
// false
@ -44,10 +43,10 @@ func ExampleCore_RecordUsage() {
c := New()
var recorded string
c.SetUsageRecorder(func(action string, qty int, _ context.Context) {
recorded = fmt.Sprintf("%s:%d", action, qty)
recorded = Concat(action, ":", Sprint(qty))
})
c.RecordUsage("ai.credits", 10)
fmt.Println(recorded)
Println(recorded)
// Output: ai.credits:10
}

View file

@ -1,15 +1,14 @@
package core_test
import (
"fmt"
. "dappco.re/go/core"
)
func ExampleE() {
err := E("cache.Get", "key not found", nil)
fmt.Println(Operation(err))
fmt.Println(ErrorMessage(err))
Println(Operation(err))
Println(ErrorMessage(err))
// Output:
// cache.Get
// key not found
@ -18,8 +17,8 @@ func ExampleE() {
func ExampleWrap() {
cause := NewError("connection refused")
err := Wrap(cause, "database.Connect", "failed to reach host")
fmt.Println(Operation(err))
fmt.Println(Is(err, cause))
Println(Operation(err))
Println(Is(err, cause))
// Output:
// database.Connect
// true
@ -29,6 +28,6 @@ func ExampleRoot() {
cause := NewError("original")
wrapped := Wrap(cause, "op1", "first wrap")
double := Wrap(wrapped, "op2", "second wrap")
fmt.Println(Root(double))
Println(Root(double))
// Output: original
}

View file

@ -198,7 +198,7 @@ func TestError_ErrorJoin_Good(t *testing.T) {
func TestError_ErrorPanic_Reports_Good(t *testing.T) {
dir := t.TempDir()
path := dir + "/crashes.json"
path := Path(dir, "crashes.json")
// Create ErrorPanic with file output
c := New()
@ -213,7 +213,7 @@ func TestError_ErrorPanic_Reports_Good(t *testing.T) {
func TestError_ErrorPanic_CrashFile_Good(t *testing.T) {
dir := t.TempDir()
path := dir + "/crashes.json"
path := Path(dir, "crashes.json")
// Create Core, trigger a panic through SafeGo, check crash file
// ErrorPanic.filePath is unexported — but we can test via the package-level

View file

@ -2,7 +2,6 @@ package core_test
import (
"context"
"fmt"
. "dappco.re/go/core"
)
@ -14,7 +13,7 @@ func ExampleNew() {
WithOption("name", "my-app"),
WithServiceLock(),
)
fmt.Println(c.App().Name)
Println(c.App().Name)
// Output: my-app
}
@ -31,7 +30,7 @@ func ExampleNew_withService() {
}),
)
c.ServiceStartup(context.Background(), nil)
fmt.Println(c.Services())
Println(c.Services())
c.ServiceShutdown(context.Background())
// Output is non-deterministic (map order), so no Output comment
}
@ -44,9 +43,9 @@ func ExampleNewOptions() {
Option{Key: "port", Value: 8080},
Option{Key: "debug", Value: true},
)
fmt.Println(opts.String("name"))
fmt.Println(opts.Int("port"))
fmt.Println(opts.Bool("debug"))
Println(opts.String("name"))
Println(opts.Int("port"))
Println(opts.Bool("debug"))
// Output:
// brain
// 8080
@ -58,7 +57,7 @@ func ExampleNewOptions() {
func ExampleResult() {
r := Result{Value: "hello", OK: true}
if r.OK {
fmt.Println(r.Value)
Println(r.Value)
}
// Output: hello
}
@ -69,9 +68,9 @@ func ExampleCore_Action_register() {
c := New()
c.Action("greet", func(_ context.Context, opts Options) Result {
name := opts.String("name")
return Result{Value: "hello " + name, OK: true}
return Result{Value: Concat("hello ", name), OK: true}
})
fmt.Println(c.Action("greet").Exists())
Println(c.Action("greet").Exists())
// Output: true
}
@ -87,7 +86,7 @@ func ExampleCore_Action_invoke() {
Option{Key: "a", Value: 3},
Option{Key: "b", Value: 4},
))
fmt.Println(r.Value)
Println(r.Value)
// Output: 7
}
@ -96,7 +95,7 @@ func ExampleCore_Actions() {
c.Action("process.run", func(_ context.Context, _ Options) Result { return Result{OK: true} })
c.Action("brain.recall", func(_ context.Context, _ Options) Result { return Result{OK: true} })
fmt.Println(c.Actions())
Println(c.Actions())
// Output: [process.run brain.recall]
}
@ -123,7 +122,7 @@ func ExampleCore_Task() {
})
c.Task("pipeline").Run(context.Background(), c, NewOptions())
fmt.Println(order)
Println(order)
// Output: ab
}
@ -134,9 +133,9 @@ func ExampleNewRegistry() {
r.Set("alpha", "first")
r.Set("bravo", "second")
fmt.Println(r.Has("alpha"))
fmt.Println(r.Names())
fmt.Println(r.Len())
Println(r.Has("alpha"))
Println(r.Names())
Println(r.Len())
// Output:
// true
// [alpha bravo]
@ -149,7 +148,7 @@ func ExampleRegistry_Lock() {
r.Lock()
result := r.Set("beta", "second")
fmt.Println(result.OK)
Println(result.OK)
// Output: false
}
@ -159,9 +158,9 @@ func ExampleRegistry_Seal() {
r.Seal()
// Can update existing
fmt.Println(r.Set("alpha", "updated").OK)
Println(r.Set("alpha", "updated").OK)
// Can't add new
fmt.Println(r.Set("beta", "new").OK)
Println(r.Set("beta", "new").OK)
// Output:
// true
// false
@ -172,8 +171,8 @@ func ExampleRegistry_Seal() {
func ExampleCore_Entitled_default() {
c := New()
e := c.Entitled("anything")
fmt.Println(e.Allowed)
fmt.Println(e.Unlimited)
Println(e.Allowed)
Println(e.Unlimited)
// Output:
// true
// true
@ -188,9 +187,9 @@ func ExampleCore_Entitled_custom() {
return Entitlement{Allowed: true, Unlimited: true}
})
fmt.Println(c.Entitled("basic").Allowed)
fmt.Println(c.Entitled("premium").Allowed)
fmt.Println(c.Entitled("premium").Reason)
Println(c.Entitled("basic").Allowed)
Println(c.Entitled("premium").Allowed)
Println(c.Entitled("premium").Reason)
// Output:
// true
// false
@ -199,8 +198,8 @@ func ExampleCore_Entitled_custom() {
func ExampleEntitlement_NearLimit() {
e := Entitlement{Allowed: true, Limit: 100, Used: 85, Remaining: 15}
fmt.Println(e.NearLimit(0.8))
fmt.Println(e.UsagePercent())
Println(e.NearLimit(0.8))
Println(e.UsagePercent())
// Output:
// true
// 85
@ -211,16 +210,16 @@ func ExampleEntitlement_NearLimit() {
func ExampleCore_Process() {
c := New()
// No go-process registered — permission by registration
fmt.Println(c.Process().Exists())
Println(c.Process().Exists())
// Register a mock process handler
c.Action("process.run", func(_ context.Context, opts Options) Result {
return Result{Value: "output of " + opts.String("command"), OK: true}
return Result{Value: Concat("output of ", opts.String("command")), OK: true}
})
fmt.Println(c.Process().Exists())
Println(c.Process().Exists())
r := c.Process().Run(context.Background(), "echo", "hello")
fmt.Println(r.Value)
Println(r.Value)
// Output:
// false
// true
@ -235,7 +234,7 @@ func ExampleJSONMarshal() {
Port int `json:"port"`
}
r := JSONMarshal(config{Host: "localhost", Port: 8080})
fmt.Println(string(r.Value.([]byte)))
Println(string(r.Value.([]byte)))
// Output: {"host":"localhost","port":8080}
}
@ -246,7 +245,7 @@ func ExampleJSONUnmarshalString() {
}
var cfg config
JSONUnmarshalString(`{"host":"localhost","port":8080}`, &cfg)
fmt.Println(cfg.Host, cfg.Port)
Println(cfg.Host, cfg.Port)
// Output: localhost 8080
}
@ -254,15 +253,15 @@ func ExampleJSONUnmarshalString() {
func ExampleID() {
id := ID()
fmt.Println(HasPrefix(id, "id-"))
Println(HasPrefix(id, "id-"))
// Output: true
}
func ExampleValidateName() {
fmt.Println(ValidateName("brain").OK)
fmt.Println(ValidateName("").OK)
fmt.Println(ValidateName("..").OK)
fmt.Println(ValidateName("path/traversal").OK)
Println(ValidateName("brain").OK)
Println(ValidateName("").OK)
Println(ValidateName("..").OK)
Println(ValidateName("path/traversal").OK)
// Output:
// true
// false
@ -271,9 +270,9 @@ func ExampleValidateName() {
}
func ExampleSanitisePath() {
fmt.Println(SanitisePath("../../etc/passwd"))
fmt.Println(SanitisePath(""))
fmt.Println(SanitisePath("/some/path/file.txt"))
Println(SanitisePath("../../etc/passwd"))
Println(SanitisePath(""))
Println(SanitisePath("/some/path/file.txt"))
// Output:
// passwd
// invalid
@ -286,12 +285,12 @@ func ExampleCore_Command() {
c := New()
c.Command("deploy/to/homelab", Command{
Action: func(opts Options) Result {
return Result{Value: "deployed to " + opts.String("_arg"), OK: true}
return Result{Value: Concat("deployed to ", opts.String("_arg")), OK: true}
},
})
r := c.Cli().Run("deploy", "to", "homelab")
fmt.Println(r.OK)
Println(r.OK)
// Output: true
}
@ -303,9 +302,9 @@ func ExampleConfig() {
c.Config().Set("database.port", 5432)
c.Config().Enable("dark-mode")
fmt.Println(c.Config().String("database.host"))
fmt.Println(c.Config().Int("database.port"))
fmt.Println(c.Config().Enabled("dark-mode"))
Println(c.Config().String("database.host"))
Println(c.Config().Int("database.port"))
Println(c.Config().Enabled("dark-mode"))
// Output:
// localhost
// 5432

View file

@ -1,7 +1,6 @@
package core_test
import (
"fmt"
. "dappco.re/go/core"
)
@ -15,7 +14,7 @@ func ExampleFs_WriteAtomic() {
f.WriteAtomic(path, `{"status":"completed"}`)
r := f.Read(path)
fmt.Println(r.Value)
Println(r.Value)
// Output: {"status":"completed"}
}
@ -32,12 +31,12 @@ func ExampleFs_NewUnrestricted() {
unrestricted := sandbox.NewUnrestricted()
r := unrestricted.Read(outside)
fmt.Println(r.Value)
Println(r.Value)
// Output: hello
}
func ExampleFs_Root() {
f := (&Fs{}).New("/srv/workspaces")
fmt.Println(f.Root())
Println(f.Root())
// Output: /srv/workspaces
}

View file

@ -75,7 +75,7 @@ type mockTranslator struct {
}
func (m *mockTranslator) Translate(id string, args ...any) Result {
return Result{"translated:" + id, true}
return Result{Concat("translated:", id), true}
}
func (m *mockTranslator) SetLanguage(lang string) error { m.lang = lang; return nil }
func (m *mockTranslator) Language() string { return m.lang }

View file

@ -1,18 +1,17 @@
package core_test
import (
"fmt"
. "dappco.re/go/core"
)
func ExampleEnv() {
fmt.Println(Env("OS")) // e.g. "darwin"
fmt.Println(Env("ARCH")) // e.g. "arm64"
Println(Env("OS")) // e.g. "darwin"
Println(Env("ARCH")) // e.g. "arm64"
}
func ExampleEnvKeys() {
keys := EnvKeys()
fmt.Println(len(keys) > 0)
Println(len(keys) > 0)
// Output: true
}

View file

@ -1,7 +1,6 @@
package core_test
import (
"fmt"
. "dappco.re/go/core"
)
@ -10,9 +9,9 @@ func ExampleCore_Lock() {
c := New()
lock := c.Lock("drain")
lock.Mutex.Lock()
fmt.Println("locked")
Println("locked")
lock.Mutex.Unlock()
fmt.Println("unlocked")
Println("unlocked")
// Output:
// locked
// unlocked

View file

@ -1,35 +1,34 @@
package core_test
import (
"fmt"
. "dappco.re/go/core"
)
func ExampleJoinPath() {
fmt.Println(JoinPath("deploy", "to", "homelab"))
Println(JoinPath("deploy", "to", "homelab"))
// Output: deploy/to/homelab
}
func ExamplePathBase() {
fmt.Println(PathBase("/srv/workspaces/alpha"))
Println(PathBase("/srv/workspaces/alpha"))
// Output: alpha
}
func ExamplePathDir() {
fmt.Println(PathDir("/srv/workspaces/alpha"))
Println(PathDir("/srv/workspaces/alpha"))
// Output: /srv/workspaces
}
func ExamplePathExt() {
fmt.Println(PathExt("report.pdf"))
Println(PathExt("report.pdf"))
// Output: .pdf
}
func ExampleCleanPath() {
fmt.Println(CleanPath("/tmp//file", "/"))
fmt.Println(CleanPath("a/b/../c", "/"))
fmt.Println(CleanPath("deploy/to/homelab", "/"))
Println(CleanPath("/tmp//file", "/"))
Println(CleanPath("a/b/../c", "/"))
Println(CleanPath("deploy/to/homelab", "/"))
// Output:
// /tmp/file
// a/c

View file

@ -15,7 +15,7 @@ func TestProcess_Run_Good(t *testing.T) {
// Register a mock process handler
c.Action("process.run", func(_ context.Context, opts Options) Result {
cmd := opts.String("command")
return Result{Value: "output of " + cmd, OK: true}
return Result{Value: Concat("output of ", cmd), OK: true}
})
r := c.Process().Run(context.Background(), "git", "log")
@ -46,7 +46,7 @@ func TestProcess_RunIn_Good(t *testing.T) {
c.Action("process.run", func(_ context.Context, opts Options) Result {
dir := opts.String("dir")
cmd := opts.String("command")
return Result{Value: cmd + " in " + dir, OK: true}
return Result{Value: Concat(cmd, " in ", dir), OK: true}
})
r := c.Process().RunIn(context.Background(), "/repo", "go", "test")
@ -126,7 +126,7 @@ func TestProcess_Ugly_PermissionByRegistration(t *testing.T) {
// Full Core
full := New()
full.Action("process.run", func(_ context.Context, opts Options) Result {
return Result{Value: "executed " + opts.String("command"), OK: true}
return Result{Value: Concat("executed ", opts.String("command")), OK: true}
})
// Sandboxed Core

View file

@ -1,7 +1,6 @@
package core_test
import (
"fmt"
. "dappco.re/go/core"
)
@ -10,7 +9,7 @@ func ExampleRegistry_Set() {
r := NewRegistry[string]()
r.Set("alpha", "first")
r.Set("bravo", "second")
fmt.Println(r.Get("alpha").Value)
Println(r.Get("alpha").Value)
// Output: first
}
@ -19,7 +18,7 @@ func ExampleRegistry_Names() {
r.Set("charlie", 3)
r.Set("alpha", 1)
r.Set("bravo", 2)
fmt.Println(r.Names())
Println(r.Names())
// Output: [charlie alpha bravo]
}
@ -30,7 +29,7 @@ func ExampleRegistry_List() {
r.Set("brain.recall", "recall")
items := r.List("process.*")
fmt.Println(len(items))
Println(len(items))
// Output: 2
}
@ -42,7 +41,7 @@ func ExampleRegistry_Each() {
sum := 0
r.Each(func(_ string, v int) { sum += v })
fmt.Println(sum)
Println(sum)
// Output: 6
}
@ -54,17 +53,17 @@ func ExampleRegistry_Disable() {
var names []string
r.Each(func(name string, _ string) { names = append(names, name) })
fmt.Println(names)
Println(names)
// Output: [bravo]
}
func ExampleRegistry_Delete() {
r := NewRegistry[string]()
r.Set("temp", "value")
fmt.Println(r.Has("temp"))
Println(r.Has("temp"))
r.Delete("temp")
fmt.Println(r.Has("temp"))
Println(r.Has("temp"))
// Output:
// true
// false

View file

@ -2,7 +2,6 @@ package core_test
import (
"context"
"fmt"
. "dappco.re/go/core"
)
@ -17,7 +16,7 @@ func ExampleServiceFor() {
)
svc := c.Service("cache")
fmt.Println(svc.OK)
Println(svc.OK)
// Output: true
}
@ -31,7 +30,7 @@ func ExampleWithService() {
}),
)
c.ServiceStartup(context.Background(), nil)
fmt.Println(started)
Println(started)
c.ServiceShutdown(context.Background())
// Output: true
}
@ -46,6 +45,6 @@ func ExampleWithServiceLock() {
// Can't register after lock
r := c.Service("blocked", Service{})
fmt.Println(r.OK)
Println(r.OK)
// Output: false
}

View file

@ -1,14 +1,13 @@
package core_test
import (
"fmt"
. "dappco.re/go/core"
)
func ExampleContains() {
fmt.Println(Contains("hello world", "world"))
fmt.Println(Contains("hello world", "mars"))
Println(Contains("hello world", "world"))
Println(Contains("hello world", "mars"))
// Output:
// true
// false
@ -16,21 +15,21 @@ func ExampleContains() {
func ExampleSplit() {
parts := Split("deploy/to/homelab", "/")
fmt.Println(parts)
Println(parts)
// Output: [deploy to homelab]
}
func ExampleJoin() {
fmt.Println(Join("/", "deploy", "to", "homelab"))
Println(Join("/", "deploy", "to", "homelab"))
// Output: deploy/to/homelab
}
func ExampleConcat() {
fmt.Println(Concat("hello", " ", "world"))
Println(Concat("hello", " ", "world"))
// Output: hello world
}
func ExampleTrim() {
fmt.Println(Trim(" spaced "))
Println(Trim(" spaced "))
// Output: spaced
}

View file

@ -2,7 +2,6 @@ package core_test
import (
"context"
"fmt"
. "dappco.re/go/core"
)
@ -32,8 +31,8 @@ func ExampleTask_Run() {
})
r := c.Task("pipe").Run(context.Background(), c, NewOptions())
fmt.Println(order)
fmt.Println(r.Value)
Println(order)
Println(r.Value)
// Output:
// ab
// got:from-a
@ -46,6 +45,6 @@ func ExampleCore_PerformAsync() {
})
r := c.PerformAsync("bg.work", NewOptions())
fmt.Println(HasPrefix(r.Value.(string), "id-"))
Println(HasPrefix(r.Value.(string), "id-"))
// Output: true
}

View file

@ -68,6 +68,13 @@ func SanitisePath(path string) string {
// --- I/O ---
// Println prints values to stdout with a newline. Replaces fmt.Println.
//
// core.Println("hello", 42, true)
func Println(args ...any) {
fmt.Println(args...)
}
// Print writes a formatted line to a writer, defaulting to os.Stdout.
//
// core.Print(nil, "hello %s", "world") // → stdout