summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/db/client.go24
-rw-r--r--pkg/gitlab/issue.go5
2 files changed, 26 insertions, 3 deletions
diff --git a/pkg/db/client.go b/pkg/db/client.go
index a656505..4f43403 100644
--- a/pkg/db/client.go
+++ b/pkg/db/client.go
@@ -1,17 +1,26 @@
package db
import (
+ "bytes"
+ "fmt"
+ "io/ioutil"
"os"
"path/filepath"
+ "github.com/xlgmokha/x/pkg/env"
+ "github.com/xlgmokha/x/pkg/serde"
"github.com/xlgmokha/x/pkg/x"
)
-type Storage[T any] struct {
+type Paramable interface {
+ ToParam() string
+}
+
+type Storage[T Paramable] struct {
dir string
}
-func New[T any](dir string) *Storage[T] {
+func New[T Paramable](dir string) *Storage[T] {
fullPath := x.Must(filepath.Abs(dir))
x.Check(os.MkdirAll(fullPath, 0700))
@@ -21,5 +30,14 @@ func New[T any](dir string) *Storage[T] {
}
func (db *Storage[T]) Save(item T) error {
- return nil
+ w := new(bytes.Buffer)
+ x.Check(serde.To(w, item, serde.YAML))
+ if env.Fetch("DUMP", "") != "" {
+ fmt.Println(w.String())
+ }
+ return ioutil.WriteFile(
+ fmt.Sprintf("%v/%v.yaml", db.dir, item.ToParam()),
+ w.Bytes(),
+ 0700,
+ )
}
diff --git a/pkg/gitlab/issue.go b/pkg/gitlab/issue.go
index 30e95ab..8251915 100644
--- a/pkg/gitlab/issue.go
+++ b/pkg/gitlab/issue.go
@@ -1,6 +1,7 @@
package gitlab
import (
+ "fmt"
"io"
"time"
@@ -27,6 +28,10 @@ type Issue struct {
Labels []string `json:"labels"`
}
+func (issue *Issue) ToParam() string {
+ return fmt.Sprintf("%v", issue.ID)
+}
+
func FromIssues(r io.Reader) ([]Issue, error) {
return serde.From[[]Issue](r, serde.JSON)
}