From 432fb9ba720320385c85d048c91444a6488790ea Mon Sep 17 00:00:00 2001 From: Phillip Michelsen Date: Wed, 18 Feb 2026 15:26:17 +0800 Subject: [PATCH] Migation to monorepo --- chron-core/cmd/main.go | 4 + chron-core/errors.go | 1 + chron-core/go.mod | 8 ++ chron-core/go.sum | 4 + {core => chron-core}/interfaces.go | 2 +- {core => chron-core}/ledger.go | 11 +-- {core => chron-core}/types.go | 2 +- chron-note/go.mod | 3 + cmd/chron-cli/main.go | 143 ----------------------------- core/errors.go | 1 - go.mod | 20 ---- go.sum | 27 ------ go.work | 6 ++ 13 files changed, 33 insertions(+), 199 deletions(-) create mode 100644 chron-core/cmd/main.go create mode 100644 chron-core/errors.go create mode 100644 chron-core/go.mod create mode 100644 chron-core/go.sum rename {core => chron-core}/interfaces.go (97%) rename {core => chron-core}/ledger.go (98%) rename {core => chron-core}/types.go (97%) create mode 100644 chron-note/go.mod delete mode 100644 cmd/chron-cli/main.go delete mode 100644 core/errors.go delete mode 100644 go.mod delete mode 100644 go.sum create mode 100644 go.work diff --git a/chron-core/cmd/main.go b/chron-core/cmd/main.go new file mode 100644 index 0000000..da29a2c --- /dev/null +++ b/chron-core/cmd/main.go @@ -0,0 +1,4 @@ +package main + +func main() { +} diff --git a/chron-core/errors.go b/chron-core/errors.go new file mode 100644 index 0000000..65e8feb --- /dev/null +++ b/chron-core/errors.go @@ -0,0 +1 @@ +package chroncore diff --git a/chron-core/go.mod b/chron-core/go.mod new file mode 100644 index 0000000..fc65006 --- /dev/null +++ b/chron-core/go.mod @@ -0,0 +1,8 @@ +module git.michelsen.id/phill/chron/chron-core + +go 1.25.7 + +require ( + github.com/klauspost/cpuid/v2 v2.0.9 // indirect + lukechampine.com/blake3 v1.4.1 // indirect +) diff --git a/chron-core/go.sum b/chron-core/go.sum new file mode 100644 index 0000000..634c7b5 --- /dev/null +++ b/chron-core/go.sum @@ -0,0 +1,4 @@ +github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +lukechampine.com/blake3 v1.4.1 h1:I3Smz7gso8w4/TunLKec6K2fn+kyKtDxr/xcQEN84Wg= +lukechampine.com/blake3 v1.4.1/go.mod h1:QFosUxmjB8mnrWFSNwKmvxHpfY72bmD2tQ0kBMM3kwo= diff --git a/core/interfaces.go b/chron-core/interfaces.go similarity index 97% rename from core/interfaces.go rename to chron-core/interfaces.go index 7d6f8cf..b295470 100644 --- a/core/interfaces.go +++ b/chron-core/interfaces.go @@ -1,4 +1,4 @@ -package core +package chroncore import "context" diff --git a/core/ledger.go b/chron-core/ledger.go similarity index 98% rename from core/ledger.go rename to chron-core/ledger.go index 8305fd3..c544fcd 100644 --- a/core/ledger.go +++ b/chron-core/ledger.go @@ -1,9 +1,10 @@ -package core +package chroncore import ( "bytes" "context" "errors" + "slices" "sort" "time" ) @@ -212,11 +213,9 @@ func (l *Ledger) IsAncestor(ctx context.Context, ancestor, descendant EntryID) ( found := false err := l.WalkAncestors(ctx, []EntryID{descendant}, func(e Entry) bool { - for _, p := range e.Parents { - if p == ancestor { - found = true - return false - } + if slices.Contains(e.Parents, ancestor) { + found = true + return false } return true }) diff --git a/core/types.go b/chron-core/types.go similarity index 97% rename from core/types.go rename to chron-core/types.go index 048f717..b75598a 100644 --- a/core/types.go +++ b/chron-core/types.go @@ -1,4 +1,4 @@ -package core +package chroncore import ( "bytes" diff --git a/chron-note/go.mod b/chron-note/go.mod new file mode 100644 index 0000000..7b83d16 --- /dev/null +++ b/chron-note/go.mod @@ -0,0 +1,3 @@ +module git.michelsen.id/phill/chron/chron-note + +go 1.25.7 diff --git a/cmd/chron-cli/main.go b/cmd/chron-cli/main.go deleted file mode 100644 index 083634b..0000000 --- a/cmd/chron-cli/main.go +++ /dev/null @@ -1,143 +0,0 @@ -package main - -import ( - "context" - "encoding/hex" - "errors" - "fmt" - "sort" - - "git.michelsen.id/chron/core" -) - -type InProcEntryStore struct { - entries map[core.EntryID]core.Entry -} - -func (e *InProcEntryStore) Store(ctx context.Context, entry core.Entry) error { - if _, ok := e.entries[entry.EntryID]; ok { - return errors.New("entry already exists") - } - e.entries[entry.EntryID] = entry - return nil -} - -func (e *InProcEntryStore) Load(ctx context.Context, id core.EntryID) (core.Entry, error) { - entry, ok := e.entries[id] - if !ok { - return core.Entry{}, errors.New("entry does not exist") - } - return entry, nil -} - -func (e *InProcEntryStore) Exists(ctx context.Context, id core.EntryID) (bool, error) { - _, ok := e.entries[id] - return ok, nil -} - -func (e *InProcEntryStore) Delete(ctx context.Context, id core.EntryID) error { - if _, ok := e.entries[id]; !ok { - return errors.New("entry does not exist") - } - delete(e.entries, id) - return nil -} - -type InProcReferenceStore struct { - references map[string]core.EntryID -} - -func (r *InProcReferenceStore) Set(ctx context.Context, name string, entryID core.EntryID) error { - r.references[name] = entryID - return nil -} - -func (r *InProcReferenceStore) Get(ctx context.Context, name string) (core.EntryID, bool, error) { - entryID, ok := r.references[name] - if !ok { - return core.EntryID{}, false, nil - } - return entryID, true, nil -} - -func (r *InProcReferenceStore) Delete(ctx context.Context, name string) error { - if _, ok := r.references[name]; !ok { - return errors.New("reference does not exist") - } - delete(r.references, name) - return nil -} - -func main() { - ctx := context.TODO() - - entryStore := InProcEntryStore{ - entries: make(map[core.EntryID]core.Entry), - } - referenceStore := InProcReferenceStore{ - references: make(map[string]core.EntryID), - } - - ledger, err := core.NewLedger(&entryStore, &referenceStore) - if err != nil { - fmt.Println(err) - return - } - - for i := range 1000000 { - data := fmt.Sprintf("test%d", i) - - err = ledger.Append(ctx, []byte(data)) - if err != nil { - fmt.Println(err) - return - } - } - - entries := make([]core.Entry, 0, len(entryStore.entries)) - for _, e := range entryStore.entries { - entries = append(entries, e) - } - - sort.Slice(entries, func(i, j int) bool { - if entries[i].Timestamp.Equal(entries[j].Timestamp) { - return hex.EncodeToString(entries[i].EntryID[:]) < - hex.EncodeToString(entries[j].EntryID[:]) - } - return entries[i].Timestamp.Before(entries[j].Timestamp) - }) - - headID, ok, err := referenceStore.Get(ctx, "HEAD") - if err != nil { - fmt.Println("get HEAD:", err) - return - } - if !ok { - fmt.Println("HEAD reference not set") - return - } - - isZero32 := func(b [32]byte) bool { - for _, v := range b { - if v != 0 { - return false - } - } - return true - } - - curID := headID - for { - ent, err := entryStore.Load(ctx, curID) - if err != nil { - return - } - - if isZero32(ent.Parents) { - break - } - - // Follow the linked list backwards - curID = core.EntryID(ent.Parents) - } -} diff --git a/core/errors.go b/core/errors.go deleted file mode 100644 index 9a8bc95..0000000 --- a/core/errors.go +++ /dev/null @@ -1 +0,0 @@ -package core diff --git a/go.mod b/go.mod deleted file mode 100644 index a50bc2c..0000000 --- a/go.mod +++ /dev/null @@ -1,20 +0,0 @@ -module git.michelsen.id/chron - -go 1.25.5 - -require github.com/google/uuid v1.6.0 - -require ( - github.com/dustin/go-humanize v1.0.1 // indirect - github.com/klauspost/cpuid/v2 v2.0.9 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect - github.com/ncruces/go-strftime v1.0.0 // indirect - github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect - golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect - golang.org/x/sys v0.37.0 // indirect - lukechampine.com/blake3 v1.4.1 // indirect - modernc.org/libc v1.67.6 // indirect - modernc.org/mathutil v1.7.1 // indirect - modernc.org/memory v1.11.0 // indirect - modernc.org/sqlite v1.45.0 // indirect -) diff --git a/go.sum b/go.sum deleted file mode 100644 index 68fa08e..0000000 --- a/go.sum +++ /dev/null @@ -1,27 +0,0 @@ -github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= -github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= -github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w= -github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= -github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= -github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= -golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY= -golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= -golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -lukechampine.com/blake3 v1.4.1 h1:I3Smz7gso8w4/TunLKec6K2fn+kyKtDxr/xcQEN84Wg= -lukechampine.com/blake3 v1.4.1/go.mod h1:QFosUxmjB8mnrWFSNwKmvxHpfY72bmD2tQ0kBMM3kwo= -modernc.org/libc v1.67.6 h1:eVOQvpModVLKOdT+LvBPjdQqfrZq+pC39BygcT+E7OI= -modernc.org/libc v1.67.6/go.mod h1:JAhxUVlolfYDErnwiqaLvUqc8nfb2r6S6slAgZOnaiE= -modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU= -modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg= -modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI= -modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw= -modernc.org/sqlite v1.45.0 h1:r51cSGzKpbptxnby+EIIz5fop4VuE4qFoVEjNvWoObs= -modernc.org/sqlite v1.45.0/go.mod h1:CzbrU2lSB1DKUusvwGz7rqEKIq+NUd8GWuBBZDs9/nA= diff --git a/go.work b/go.work new file mode 100644 index 0000000..c18c400 --- /dev/null +++ b/go.work @@ -0,0 +1,6 @@ +go 1.25.7 + +use ( + ./chron-core + ./chron-note +)