Skip to content

Commit

Permalink
use embed package instead of github.com/rakyll/statik (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame authored Feb 26, 2025
1 parent da05182 commit c8fd634
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 47 deletions.
13 changes: 2 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@ SPANNER_EMULATOR_HOST_REST ?= localhost:9020

BIN_DIR := .bin
YO_BIN := ${BIN_DIR}/yo
STATIK_BIN := ${BIN_DIR}/statik
LINT_BIN := ${BIN_DIR}/golangci-lint
WRENCH_BIN := ${BIN_DIR}/wrench

${YO_BIN}:
@mkdir -p ${BIN_DIR}
@go build -o ${YO_BIN} go.mercari.io/yo

${STATIK_BIN}:
@mkdir -p ${BIN_DIR}
@go build -o ${STATIK_BIN} github.com/rakyll/statik

${LINT_BIN}:
@mkdir -p ${BIN_DIR}
@go build -o ${LINT_BIN} github.com/golangci/golangci-lint/cmd/golangci-lint
Expand All @@ -29,24 +24,20 @@ ${WRENCH_BIN}:


.PHONY: install
install: ${WRENCH_BIN} ${YO_BIN} ${STATIK_BIN} ${LINT_BIN}
install: ${WRENCH_BIN} ${YO_BIN} ${LINT_BIN}

.PHONY: clean
clean:
rm -rf ${BIN_DIR}

.PHONY: gen
gen: gen_model gen_assets
gen: gen_model

.PHONY: gen_model
gen_model: ${YO_BIN}
rm -f ./model/*.yo.go
${YO_BIN} $(SPANNER_PROJECT_ID) $(SPANNER_INSTANCE_ID) $(SPOOL_SPANNER_DATABASE_ID) --out ./model/

.PHONY: gen_assets
gen_assets: ${STATIK_BIN}
${STATIK_BIN} -src ./db

.PHONY: lint
lint: ${LINT_BIN}
${LINT_BIN} run
Expand Down
21 changes: 2 additions & 19 deletions admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,24 @@ package spool
import (
"context"
"fmt"
"io/ioutil"

"cloud.google.com/go/spanner"
admin "cloud.google.com/go/spanner/admin/database/apiv1"
"github.com/cloudspannerecosystem/spool/internal/db"
"github.com/cloudspannerecosystem/spool/model"
"github.com/rakyll/statik/fs"
databasepb "google.golang.org/genproto/googleapis/spanner/admin/database/v1"

// Registers zip contents data.
_ "github.com/cloudspannerecosystem/spool/statik"
)

// Setup creates a new spool metadata database.
func Setup(ctx context.Context, conf *Config) error {
sfs, err := fs.New()
if err != nil {
return err
}
f, err := sfs.Open("/schema.sql")
if err != nil {
return err
}
defer func() { _ = f.Close() }()
ddl, err := ioutil.ReadAll(f)
if err != nil {
return err
}
adminClient, err := admin.NewDatabaseAdminClient(ctx, conf.ClientOptions()...)
if err != nil {
return err
}
op, err := adminClient.CreateDatabase(ctx, &databasepb.CreateDatabaseRequest{
Parent: conf.Instance(),
CreateStatement: fmt.Sprintf("CREATE DATABASE `%s`", conf.DatabaseID()),
ExtraStatements: ddlToStatements(ddl),
ExtraStatements: ddlToStatements(db.SpoolSchema),
})
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/golangci/golangci-lint v1.43.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/pkg/errors v0.9.1
github.com/rakyll/statik v0.1.7
go.mercari.io/yo v0.5.0
google.golang.org/api v0.63.0
google.golang.org/genproto v0.0.0-20211223182754-3ac035c7e7cb
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,6 @@ github.com/quasilyte/go-ruleguard/rules v0.0.0-20201231183845-9e62ed36efe1/go.mo
github.com/quasilyte/go-ruleguard/rules v0.0.0-20210428214800-545e0d2e0bf7/go.mod h1:4cgAphtvu7Ftv7vOT2ZOYhC6CvBxZixcasr8qIOTA50=
github.com/quasilyte/regex/syntax v0.0.0-20200407221936-30656e2c4a95 h1:L8QM9bvf68pVdQ3bCFZMDmnt9yqcMBro1pC7F+IPYMY=
github.com/quasilyte/regex/syntax v0.0.0-20200407221936-30656e2c4a95/go.mod h1:rlzQ04UMyJXu/aOvhd8qT+hvDrFpiwqp8MRXDY9szc0=
github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ=
github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Unghqrcc=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down
6 changes: 6 additions & 0 deletions internal/db/embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package db

import _ "embed"

//go:embed schema.sql
var SpoolSchema []byte
File renamed without changes.
13 changes: 0 additions & 13 deletions statik/statik.go

This file was deleted.

1 change: 0 additions & 1 deletion tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ package tools
import (
_ "github.com/cloudspannerecosystem/wrench"

Check failure on line 4 in tools/tools.go

View workflow job for this annotation

GitHub Actions / test

import "github.com/cloudspannerecosystem/wrench" is a program, not an importable package
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
_ "github.com/rakyll/statik"
_ "go.mercari.io/yo"
)

0 comments on commit c8fd634

Please sign in to comment.