Skip to content

Commit

Permalink
dev: init x package for experiments and porting outside
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Nov 20, 2023
1 parent a09bb5a commit 2fdf85d
Show file tree
Hide file tree
Showing 17 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion internal/config/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

xtesting "go.octolab.org/ecosystem/sparkle/internal/pkg/testing"
xtesting "go.octolab.org/ecosystem/sparkle/internal/pkg/x/testing"
)

func TestServerSerialization(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/config/sparkle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

xtesting "go.octolab.org/ecosystem/sparkle/internal/pkg/testing"
xtesting "go.octolab.org/ecosystem/sparkle/internal/pkg/x/testing"
)

func TestSparkleSerialization(t *testing.T) {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/pkg/errors/ux.go → internal/pkg/x/errors/ux.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package errors
package xerrors

// X is a pair of errors, one for a user
// and one for a developer.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build !linux && !unix && !darwin && !freebsd

package fs
package xfs

import (
"io/fs"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build darwin || freebsd

package fs
package xfs

import (
"io/fs"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build linux || unix

package fs
package xfs

import (
"io/fs"
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package xtime
import (
"time"

xassert "go.octolab.org/ecosystem/sparkle/internal/pkg/assert"
xassert "go.octolab.org/ecosystem/sparkle/internal/pkg/x/assert"
)

func IsLinear(past, future time.Time, threshold time.Duration) (is bool, shift bool) {
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions internal/plugins/obsidian/calendar/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"go.octolab.org/safe"
"go.octolab.org/unsafe"

"go.octolab.org/ecosystem/sparkle/internal/pkg/errors"
xerrors "go.octolab.org/ecosystem/sparkle/internal/pkg/x/errors"
)

const config = ".obsidian/plugins/calendar/data.json"
Expand All @@ -33,15 +33,15 @@ func LoadConfig(fs afero.Fs) (Config, error) {
return cnf, nil
}
if err != nil {
return cnf, errors.X{
return cnf, xerrors.X{
User: errConfig,
System: fmt.Errorf("cannot load config %w", err),
}
}
defer safe.Close(f, unsafe.Ignore)

if err := json.NewDecoder(f).Decode(&cnf); err != nil {
return cnf, errors.X{
return cnf, xerrors.X{
User: errConfig,
System: fmt.Errorf("cannot decode config %w", err),
}
Expand Down
6 changes: 3 additions & 3 deletions internal/plugins/obsidian/daily-notes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"go.octolab.org/safe"
"go.octolab.org/unsafe"

"go.octolab.org/ecosystem/sparkle/internal/pkg/errors"
xerrors "go.octolab.org/ecosystem/sparkle/internal/pkg/x/errors"
)

const config = ".obsidian/daily-notes.json"
Expand All @@ -29,15 +29,15 @@ func LoadConfig(fs afero.Fs) (Config, error) {
return cnf, nil
}
if err != nil {
return cnf, errors.X{
return cnf, xerrors.X{
User: errConfig,
System: fmt.Errorf("cannot load config %w", err),
}
}
defer safe.Close(f, unsafe.Ignore)

if err := json.NewDecoder(f).Decode(&cnf); err != nil {
return cnf, errors.X{
return cnf, xerrors.X{
User: errConfig,
System: fmt.Errorf("cannot decode config %w", err),
}
Expand Down
10 changes: 5 additions & 5 deletions internal/plugins/obsidian/daily-notes/diary.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"go.octolab.org/safe"
"go.octolab.org/unsafe"

"go.octolab.org/ecosystem/sparkle/internal/pkg/errors"
"go.octolab.org/ecosystem/sparkle/internal/pkg/markdown"
xerrors "go.octolab.org/ecosystem/sparkle/internal/pkg/x/errors"
)

const ext = ".md"
Expand Down Expand Up @@ -57,7 +57,7 @@ func (d *Diary) Create(
}
file, err := d.fs.OpenFile(record.Path, flag, 0644)
if err != nil {
return record, errors.X{
return record, xerrors.X{
User: errFolder,
System: fmt.Errorf("cannot open file %q: %w", record.Path, err),
}
Expand Down Expand Up @@ -85,7 +85,7 @@ func (d *Diary) Create(
)

if err := note.SaveTo(file); err != nil {
return record, errors.X{
return record, xerrors.X{
User: errFolder,
System: fmt.Errorf("cannot save file %q: %w", record.Path, err),
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func (d *Diary) template() (markdown.Document, error) {

file, err := d.fs.Open(d.cnf.Template)
if err != nil {
return empty, errors.X{
return empty, xerrors.X{
User: errTemplate,
System: fmt.Errorf("cannot load template %q: %w", d.cnf.Template, err),
}
Expand All @@ -164,7 +164,7 @@ func (d *Diary) template() (markdown.Document, error) {

var doc markdown.Document
if err := markdown.LoadFrom(file, &doc); err != nil {
return empty, errors.X{
return empty, xerrors.X{
User: errTemplate,
System: fmt.Errorf("cannot parse template %q: %w", d.cnf.Template, err),
}
Expand Down
6 changes: 3 additions & 3 deletions internal/plugins/obsidian/periodic-notes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"go.octolab.org/safe"
"go.octolab.org/unsafe"

"go.octolab.org/ecosystem/sparkle/internal/pkg/errors"
xerrors "go.octolab.org/ecosystem/sparkle/internal/pkg/x/errors"
)

const config = ".obsidian/plugins/periodic-notes/data.json"
Expand Down Expand Up @@ -48,15 +48,15 @@ func LoadConfig(fs afero.Fs) (Config, error) {
return cnf, nil
}
if err != nil {
return cnf, errors.X{
return cnf, xerrors.X{
User: errConfig,
System: fmt.Errorf("cannot load config %w", err),
}
}
defer safe.Close(f, unsafe.Ignore)

if err := json.NewDecoder(f).Decode(&cnf); err != nil {
return cnf, errors.X{
return cnf, xerrors.X{
User: errConfig,
System: fmt.Errorf("cannot decode config %w", err),
}
Expand Down
4 changes: 2 additions & 2 deletions internal/service/playbook/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"go.octolab.org/safe"
"go.octolab.org/unsafe"

"go.octolab.org/ecosystem/sparkle/internal/pkg/fs"
"go.octolab.org/ecosystem/sparkle/internal/pkg/markdown"
xfs "go.octolab.org/ecosystem/sparkle/internal/pkg/x/fs"
)

const (
Expand Down Expand Up @@ -52,7 +52,7 @@ func (service *Service) Notes(root string) ([]Note, error) {
notes = append(notes, Note{
Document: doc,
Path: path,
CreatedAt: fs.CreatedAt(info),
CreatedAt: xfs.CreatedAt(info),
UpdatedAt: info.ModTime(),
})
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/tact/logbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"regexp"
"time"

xtime "go.octolab.org/ecosystem/sparkle/internal/pkg/time"
xtime "go.octolab.org/ecosystem/sparkle/internal/pkg/x/time"
)

type Logbook interface {
Expand Down

0 comments on commit 2fdf85d

Please sign in to comment.