Reverted to Template and Update
Some checks failed
Continuous Integration / CI (push) Has been cancelled
Some checks failed
Continuous Integration / CI (push) Has been cancelled
Reverted to Template from old project dev. Updated to latest golang
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# syntax = docker/dockerfile:1-experimental
|
# syntax = docker/dockerfile:1-experimental
|
||||||
|
|
||||||
FROM --platform=${BUILDPLATFORM} golang:1.16.5-alpine AS base
|
FROM --platform=${BUILDPLATFORM} golang:1.24.3-alpine AS base
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
ENV CGO_ENABLED=1
|
ENV CGO_ENABLED=1
|
||||||
RUN apk update
|
RUN apk update
|
||||||
@@ -39,7 +39,7 @@ RUN --mount=target=. \
|
|||||||
FROM base as mod-init-base
|
FROM base as mod-init-base
|
||||||
WORKDIR /out
|
WORKDIR /out
|
||||||
COPY . .
|
COPY . .
|
||||||
ENV MODNAME goptrack
|
ENV MODNAME example
|
||||||
RUN go mod init "${MODNAME}" && go mod tidy
|
RUN go mod init "${MODNAME}" && go mod tidy
|
||||||
|
|
||||||
FROM base AS mod-tidy
|
FROM base AS mod-tidy
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
package tradebook
|
|
||||||
|
|
||||||
import (
|
|
||||||
"database/sql"
|
|
||||||
_ "modernc.org/sqlite"
|
|
||||||
)
|
|
||||||
|
|
||||||
type tradebook struct {
|
|
||||||
driver string
|
|
||||||
dsn string
|
|
||||||
db *sql.DB
|
|
||||||
}
|
|
||||||
|
|
||||||
type openOption func(*tradebook) error
|
|
||||||
|
|
||||||
func Open(opts ...openOption) (*tradebook, error) {
|
|
||||||
t := tradebook{}
|
|
||||||
// Apply Options
|
|
||||||
for _, opt := range opts {
|
|
||||||
opt(&t)
|
|
||||||
}
|
|
||||||
|
|
||||||
db, err := sql.Open(t.driver, t.dsn)
|
|
||||||
t.db = db
|
|
||||||
if (err == nil) {
|
|
||||||
err = db.Ping()
|
|
||||||
}
|
|
||||||
|
|
||||||
return &t, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func Sqlite(fpath string) openOption {
|
|
||||||
return func(t *tradebook) error {
|
|
||||||
t.driver = "sqlite"
|
|
||||||
t.dsn = fpath
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package tradebook
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestOpenSQLite(t *testing.T) {
|
|
||||||
tdir := t.TempDir()
|
|
||||||
dpath := filepath.Join(tdir, "db")
|
|
||||||
|
|
||||||
tb, err := Open(Sqlite(dpath))
|
|
||||||
if (err != nil) {
|
|
||||||
t.Errorf("Open returned error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tb == nil) {
|
|
||||||
t.Error("Db is nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
// for sqlite dsn is just a file path
|
|
||||||
if (tb.dsn != dpath) {
|
|
||||||
t.Errorf( "DSN does not match! (%v != %v).", dpath, tb.dsn)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tb.driver != "sqlite") {
|
|
||||||
t.Errorf("Driver is not sqlite (%v != %v).", tb.driver, "sqlite")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user