Skip to content

Commit

Permalink
Add main components boilerplate
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Shishkin <me@teran.dev>
  • Loading branch information
teran committed Jul 7, 2024
1 parent 92728ac commit 540fe81
Show file tree
Hide file tree
Showing 9 changed files with 405 additions and 6 deletions.
42 changes: 40 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,31 @@ builds:
env:
- CGO_ENABLED=0
goos:
- darwin
- dragonfly
- freebsd
- linux
- netbsd
- openbsd
- solaris
- windows
goarch:
# x86
- amd64
- "386"

# ARM
- arm64
- arm

# MIPS
- mips64
- mips64le
- mips
- mipsle
goamd64: ["v1", "v2", "v3"]
goarm: ["7"]
goarm: ["6", "7"]
gomips: ["hardfloat", "softfloat"]
mod_timestamp: "{{ .CommitTimestamp }}"
- id: archived-cli
main: ./cmd/cli
Expand Down Expand Up @@ -58,12 +77,31 @@ builds:
env:
- CGO_ENABLED=0
goos:
- darwin
- dragonfly
- freebsd
- linux
- netbsd
- openbsd
- solaris
- windows
goarch:
# x86
- amd64
- "386"

# ARM
- arm64
- arm

# MIPS
- mips64
- mips64le
- mips
- mipsle
goamd64: ["v1", "v2", "v3"]
goarm: ["7"]
goarm: ["6", "7"]
gomips: ["hardfloat", "softfloat"]
mod_timestamp: "{{ .CommitTimestamp }}"
archives:
- format: binary
Expand Down
162 changes: 161 additions & 1 deletion cmd/access/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,170 @@
package main

import (
"context"
"net/http"

"github.com/kelseyhightower/envconfig"
echo "github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
log "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"

htmlPresenter "github.com/teran/archived/presenter/access/html"
"github.com/teran/archived/service"
)

var (
appVersion = "n/a (dev build)"
buildTimestamp = "undefined"
)

type config struct {
Addr string `envconfig:"ADDR" default:":8080"`
LogLevel log.Level `envconfig:"LOG_LEVEL" default:"info"`
HTMLTemplateDir string `envconfig:"HTML_TEMPLATE_DIR"`
}

func main() {
panic("not implemented")
var cfg config
envconfig.MustProcess("", &cfg)

log.SetLevel(cfg.LogLevel)

lf := new(log.TextFormatter)
lf.FullTimestamp = true
log.SetFormatter(lf)

log.Infof("Initializing archived-access (%s @ %s) ...", appVersion, buildTimestamp)

g, _ := errgroup.WithContext(context.Background())

e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())

// svc := service.NewAccessService(nil, nil)
svc := service.NewMock()
svc.On("ListContainers").Return([]string{"test-container-1", "test-container-2"}, nil)
svc.On("ListVersions", "test-container-1").Return([]string{"20240706101013", "202407061101314"}, nil)
svc.On("ListObjects", "test-container-1", "20240706101013").Return([]string{
"rockylinux/9/appstream/Packages/r/rocky-indexhtml-9.0-2.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rocky-logos-ipa-90.15-2.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rocky-logos-httpd-90.15-2.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rocky-backgrounds-90.15-2.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rust-srpm-macros-17-4.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/realtime-tests-2.6-5.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rpmdevtools-9.5-1.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rpmlint-1.11-19.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/redhat-text-fonts-4.0.3-1.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/redhat-mono-fonts-4.0.3-1.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/redhat-display-fonts-4.0.3-1.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rpm-mpi-hooks-8-3.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rhel-system-roles-1.23.0-2.21.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rtkit-0.11-28.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rshim-2.0.8-1.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rdma-core-devel-48.0-1.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/redhat-rpm-config-207-1.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/regexp-1.5-37.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/redland-1.0.17-29.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rpm-plugin-systemd-inhibit-4.16.1.3-29.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rpm-plugin-syslog-4.16.1.3-29.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rpm-plugin-ima-4.16.1.3-29.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rpm-plugin-fapolicyd-4.16.1.3-29.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rpm-devel-4.16.1.3-29.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rpm-cron-4.16.1.3-29.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rpm-build-4.16.1.3-29.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rpm-apidocs-4.16.1.3-29.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/redfish-finder-0.4-9.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rig-1.1-6.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/runc-1.1.12-2.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/redis-doc-6.2.7-1.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/redis-devel-6.2.7-1.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/redis-6.2.7-1.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rubygems-devel-3.2.33-162.el9_4.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rubygems-3.2.33-162.el9_4.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rubygem-typeprof-0.15.2-162.el9_4.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rubygem-test-unit-3.3.7-162.el9_4.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rubygem-rss-0.2.9-162.el9_4.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rubygem-rexml-3.2.5-162.el9_4.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rubygem-rdoc-6.3.4.1-162.el9_4.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rubygem-rbs-1.4.0-162.el9_4.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rubygem-rake-13.0.3-162.el9_4.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rubygem-power_assert-1.2.1-162.el9_4.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rubygem-minitest-5.14.2-162.el9_4.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rubygem-irb-1.3.5-162.el9_4.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rubygem-bundler-2.2.33-162.el9_4.noarch.rpm",
"rockylinux/9/appstream/Packages/r/ruby-default-gems-3.0.7-162.el9_4.noarch.rpm",
"rockylinux/9/appstream/Packages/r/radvd-2.19-5.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rasdaemon-0.6.7-9.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rrdtool-perl-1.7.2-21.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rrdtool-1.7.2-21.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/raptor2-2.0.15-30.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rear-2.6-24.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rustfmt-1.75.0-1.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rust-std-static-wasm32-wasi-1.75.0-1.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rust-std-static-wasm32-unknown-unknown-1.75.0-1.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rust-std-static-1.75.0-1.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rust-doc-1.75.0-1.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rust-1.75.0-1.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rust-src-1.75.0-1.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rust-lldb-1.75.0-1.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rust-gdb-1.75.0-1.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rust-debugger-common-1.75.0-1.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-udpspoof-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-snmp-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-relp-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-pgsql-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-openssl-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-omamqp1-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-mysql-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-mmsnmptrapd-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-mmnormalize-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-mmkubernetes-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-mmjsonparse-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-mmfields-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-mmaudit-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-logrotate-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-kafka-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-gssapi-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-gnutls-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-elasticsearch-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-doc-8.2310.0-4.el9.noarch.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-crypto-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rsyslog-8.2310.0-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rest-0.8.1-11.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rasqal-0.9.33-18.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rubygem-mysql2-0.5.3-11.el9_0.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rpm-ostree-libs-2024.3-4.el9_4.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rpm-ostree-2024.3-4.el9_4.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/readline-devel-8.1-4.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rubygem-psych-3.3.2-162.el9_4.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rubygem-json-2.5.1-162.el9_4.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rubygem-io-console-0.5.7-162.el9_4.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rubygem-bigdecimal-3.0.0-162.el9_4.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/ruby-libs-3.0.7-162.el9_4.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/ruby-devel-3.0.7-162.el9_4.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/ruby-3.0.7-162.el9_4.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rpcgen-1.4-9.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rubygem-pg-1.2.3-7.el9.x86_64.rpm",
"rockylinux/9/appstream/Packages/r/rocky-logos-90.15-2.el9.x86_64.rpm",
}, nil)

svc.On("GetObjectURL", "test-container-1", "20240706101013", "rockylinux/9/appstream/Packages/r/rocky-logos-90.15-2.el9.x86_64.rpm").Return("http://wikipedia.org", nil)

p := htmlPresenter.New(svc, cfg.HTMLTemplateDir)
p.Register(e)

g.Go(func() error {
srv := &http.Server{
Addr: cfg.Addr,
Handler: e,
}

return srv.ListenAndServe()
})

if err := g.Wait(); err != nil {
panic(err)
}
}
13 changes: 12 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ go 1.22.5
require (
github.com/Masterminds/squirrel v1.5.4
github.com/golang-migrate/migrate/v4 v4.17.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/labstack/echo/v4 v4.12.0
github.com/lib/pq v1.10.9
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
github.com/teran/go-docker-testsuite v0.0.6
github.com/teran/go-ptr v1.1.0
github.com/teran/go-time v0.0.2
golang.org/x/sync v0.7.0
)

require (
Expand All @@ -30,6 +34,7 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
Expand All @@ -40,17 +45,21 @@ require (
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgtype v1.14.0 // indirect
github.com/jackc/pgx/v4 v4.18.3 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/sys/mountinfo v0.7.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/opencontainers/runtime-spec v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/teran/go-random v0.0.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 // indirect
go.opentelemetry.io/otel v1.26.0 // indirect
go.opentelemetry.io/otel/metric v1.26.0 // indirect
Expand All @@ -59,8 +68,10 @@ require (
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.10.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 540fe81

Please sign in to comment.