Reverted to Template and Update
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:
sjc
2025-05-06 21:01:22 -04:00
parent fd67f9ef8a
commit 1dbeb5a218
3 changed files with 2 additions and 71 deletions

View File

@@ -1,6 +1,6 @@
# 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
ENV CGO_ENABLED=1
RUN apk update
@@ -39,7 +39,7 @@ RUN --mount=target=. \
FROM base as mod-init-base
WORKDIR /out
COPY . .
ENV MODNAME goptrack
ENV MODNAME example
RUN go mod init "${MODNAME}" && go mod tidy
FROM base AS mod-tidy

View File

@@ -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
}
}

View File

@@ -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")
}
}