-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from shiguredo/feature/refactoring
Feature/refactoring
- Loading branch information
Showing
25 changed files
with
470 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"$schema": "https://docs.renovatebot.com/renovate-schema.json", | ||
"extends": [ | ||
"config:base", | ||
":timezone(Asia/Tokyo)", | ||
":combinePatchMinorReleases", | ||
":prHourlyLimitNone", | ||
":prConcurrentLimit10", | ||
"group:recommended", | ||
"group:allNonMajor", | ||
"schedule:weekly" | ||
], | ||
"dependencyDashboard": false, | ||
"packageRules": [ | ||
{ | ||
"matchUpdateTypes": ["minor", "patch", "pin", "digest"], | ||
"platformAutomerge": true, | ||
"automerge": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: ci | ||
on: | ||
push: | ||
branches-ignore: | ||
- "master" | ||
tags-ignore: | ||
- "*" | ||
|
||
jobs: | ||
build: | ||
name: ci | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: setup go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: ./go.mod | ||
cache: true | ||
cache-dependency-path: ./go.sum | ||
- run: go version | ||
- run: go fmt . | ||
- uses: dominikh/staticcheck-action@v1 | ||
with: | ||
version: "2023.1.5" | ||
install-go: false | ||
- name: Test | ||
run: make test | ||
- name: Build | ||
run: make |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: release | ||
|
||
on: | ||
push: | ||
tags: | ||
- "*" | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: ./go.mod | ||
cache: false | ||
|
||
- run: go install github.com/tcnksm/ghr@latest | ||
|
||
- name: Build | ||
run: | | ||
GOOS=linux GOARCH=amd64 go build -o dist/sora-archive-uploader_linux_amd64 cmd/sora-archive-uploader/main.go | ||
GOOS=darwin GOARCH=amd64 go build -o dist/sora-archive-uploader_darwin_amd64 cmd/sora-archive-uploader/main.go | ||
GOOS=darwin GOARCH=arm64 go build -o dist/sora-archive-uploader_darwin_arm64 cmd/sora-archive-uploader/main.go | ||
gzip dist/* | ||
- name: Release | ||
run: | | ||
ghr -t "${{ secrets.GITHUB_TOKEN }}" -u "${{ github.repository_owner }}" -r "sora-archive-uploader" --replace "${GITHUB_REF##*/}" dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
bin/* | ||
config.toml | ||
*.jsonl | ||
config.ini | ||
*.jsonl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# 変更履歴 | ||
|
||
- CHANGE | ||
- 下位互換のない変更 | ||
- UPDATE | ||
- 下位互換がある変更 | ||
- ADD | ||
- 下位互換がある追加 | ||
- FIX | ||
- バグ修正 | ||
|
||
## develop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,7 @@ | ||
VERSION := 2022.1.0 | ||
REVISION := $(shell git rev-parse --short HEAD) | ||
BUILD_DATE := $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") | ||
LDFLAGS := "-X main.version=$(VERSION) -X main.revision=$(REVISION) -X main.buildDate=$(BUILD_DATE)" | ||
LDFLAGS_PROD := "-s -w -X main.version=$(VERSION) -X main.revision=$(REVISION)" | ||
.PHONY: all test | ||
|
||
export GO1111MODULE=on | ||
export CWD=$(dir $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
|
||
.PHONY: all sora-archive-uploader-dev sora-archive-uploader-prod | ||
all: sora-archive-uploader-dev | ||
|
||
sora-archive-uploader-dev: cmd/sora-archive-uploader/main.go | ||
go build -race -ldflags $(LDFLAGS) -o bin/$@ $< | ||
|
||
sora-archive-uploader-prod: cmd/sora-archive-uploader/main.go | ||
go build -ldflags $(LDFLAGS_PROD) -o bin/$@ $< | ||
all: | ||
go build -o bin/sora-archive-uploader cmd/sora-archive-uploader/main.go | ||
|
||
test: | ||
go test -v | ||
go test -race -v ./s3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2023.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,79 @@ | ||
package archive | ||
|
||
import ( | ||
"github.com/BurntSushi/toml" | ||
_ "embed" | ||
|
||
"gopkg.in/ini.v1" | ||
) | ||
|
||
//go:embed VERSION | ||
var Version string | ||
|
||
const ( | ||
DefaultLogDir = "." | ||
DefaultLogName = "sora-archive-uploader.jsonl" | ||
|
||
// megabytes | ||
DefaultLogRotateMaxSize = 200 | ||
DefaultLogRotateMaxBackups = 7 | ||
// days | ||
DefaultLogRotateMaxAge = 30 | ||
) | ||
|
||
type Config struct { | ||
Debug bool `toml:"debug"` | ||
Debug bool `ini:"debug"` | ||
|
||
LogDir string `toml:"log_dir"` | ||
LogName string `toml:"log_name"` | ||
LogStdOut bool `toml:"log_std_out"` | ||
LogRotateMaxSize int `toml:"log_rotate_max_size"` | ||
LogRotateMaxBackups int `toml:"log_rotate_max_backups"` | ||
LogRotateMaxAge int `toml:"log_rotate_max_age"` | ||
LogRotateCompress bool `toml:"log_rotate_compress"` | ||
LogDir string `ini:"log_dir"` | ||
LogName string `ini:"log_name"` | ||
LogStdout bool `ini:"log_stdout"` | ||
|
||
ObjectStorageEndpoint string `toml:"object_storage_endpoint"` | ||
ObjectStorageBucketName string `toml:"object_storage_bucket_name"` | ||
ObjectStorageAccessKeyID string `toml:"object_storage_access_key_id"` | ||
ObjectStorageSecretAccessKey string `toml:"object_storage_secret_access_key"` | ||
LogRotateMaxSize int `ini:"log_rotate_max_size"` | ||
LogRotateMaxBackups int `ini:"log_rotate_max_backups"` | ||
LogRotateMaxAge int `ini:"log_rotate_max_age"` | ||
LogRotateCompress bool `ini:"log_rotate_compress"` | ||
|
||
SoraArchiveDirFullPath string `toml:"archive_dir_full_path"` | ||
SoraEvacuateDirFullPath string `toml:"evacuate_dir_full_path"` | ||
ObjectStorageEndpoint string `ini:"object_storage_endpoint"` | ||
ObjectStorageBucketName string `ini:"object_storage_bucket_name"` | ||
ObjectStorageAccessKeyID string `ini:"object_storage_access_key_id"` | ||
ObjectStorageSecretAccessKey string `ini:"object_storage_secret_access_key"` | ||
|
||
UploadWorkers int `toml:"upload_workers"` | ||
SoraArchiveDirFullPath string `ini:"archive_dir_full_path"` | ||
SoraEvacuateDirFullPath string `ini:"evacuate_dir_full_path"` | ||
|
||
UploadedFileCacheSize int `toml:"uploaded_file_cache_size"` | ||
UploadWorkers int `ini:"upload_workers"` | ||
|
||
WebhookEndpointURL string `toml:"webhook_endpoint_url"` | ||
WebhookEndpointHealthCheckURL string `toml:"webhook_endpoint_health_check_url"` | ||
// 1 ファイルあたりのアップロードレート制限 | ||
UploadFileRateLimitMbps int `ini:"upload_file_rate_limit_mbps"` | ||
|
||
WebhookTypeHeaderName string `toml:"webhook_type_header_name"` | ||
WebhookTypeArchiveUploaded string `toml:"webhook_type_archive_uploaded"` | ||
WebhookTypeSplitArchiveUploaded string `toml:"webhook_type_split_archive_uploaded"` | ||
WebhookTypeSplitArchiveEndUploaded string `toml:"webhook_type_split_archive_end_uploaded"` | ||
WebhookTypeReportUploaded string `toml:"webhook_type_report_uploaded"` | ||
UploadedFileCacheSize int `ini:"uploaded_file_cache_size"` | ||
|
||
WebhookBasicAuthUsername string `toml:"webhook_basic_auth_username"` | ||
WebhookBasicAuthPassword string `toml:"webhook_basic_auth_password"` | ||
WebhookEndpointURL string `ini:"webhook_endpoint_url"` | ||
WebhookEndpointHealthCheckURL string `ini:"webhook_endpoint_health_check_url"` | ||
|
||
WebhookRequestTimeoutS int32 `toml:"webhook_request_timeout_s"` | ||
WebhookTypeHeaderName string `ini:"webhook_type_header_name"` | ||
WebhookTypeArchiveUploaded string `ini:"webhook_type_archive_uploaded"` | ||
WebhookTypeSplitArchiveUploaded string `ini:"webhook_type_split_archive_uploaded"` | ||
WebhookTypeSplitArchiveEndUploaded string `ini:"webhook_type_split_archive_end_uploaded"` | ||
WebhookTypeReportUploaded string `ini:"webhook_type_report_uploaded"` | ||
|
||
WebhookTlsVerifyCacertPath string `toml:"webhook_tls_verify_cacert_path"` | ||
WebhookTlsFullchainPath string `toml:"webhook_tls_fullchain_path"` | ||
WebhookTlsPrivkeyPath string `toml:"webhook_tls_privkey_path"` | ||
WebhookBasicAuthUsername string `ini:"webhook_basic_auth_username"` | ||
WebhookBasicAuthPassword string `ini:"webhook_basic_auth_password"` | ||
|
||
WebhookRequestTimeoutS int32 `ini:"webhook_request_timeout_s"` | ||
|
||
WebhookTLSVerifyCacertPath string `ini:"webhook_tls_verify_cacert_path"` | ||
WebhookTLSFullchainPath string `ini:"webhook_tls_fullchain_path"` | ||
WebhookTLSPrivkeyPath string `ini:"webhook_tls_privkey_path"` | ||
} | ||
|
||
func initConfig(data []byte, config interface{}) error { | ||
if err := toml.Unmarshal(data, config); err != nil { | ||
return err | ||
func newConfig(configFilePath string) (*Config, error) { | ||
config := new(Config) | ||
iniConfig, err := ini.InsensitiveLoad(configFilePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// TODO: 初期値 | ||
return nil | ||
if err := iniConfig.StrictMapTo(config); err != nil { | ||
return nil, err | ||
} | ||
return config, nil | ||
} |
Oops, something went wrong.