add user-facing cli to makefile, and config master address through .env
This commit is contained in:
parent
efd008f12a
commit
10e0c22108
@ -21,3 +21,7 @@ DB_HEALTH_CHECK_PERIOD=5s
|
||||
# User Defaults and Billing
|
||||
DEFAULT_STORAGE_LIMIT_GB=1
|
||||
PRICE_PER_GB_USD=0.50
|
||||
|
||||
# Bitcoin Payment Configuration
|
||||
BITCOIN_MASTER_ADDRESS=bc1qyour_bitcoin_address_here
|
||||
BITCOIN_NETWORK=mainnet
|
||||
|
||||
14
Makefile
14
Makefile
@ -1,5 +1,6 @@
|
||||
BINARY = termcloud
|
||||
ADMIN_BINARY = termcloud-admin
|
||||
CLI_BINARY = tcman
|
||||
|
||||
include .env
|
||||
export
|
||||
@ -7,6 +8,7 @@ export
|
||||
build: clean
|
||||
go build -o build/${BINARY} cmd/${BINARY}/main.go
|
||||
go build -o build/${ADMIN_BINARY} cmd/admin/main.go
|
||||
go build -o build/${CLI_BINARY} cmd/${CLI_BINARY}/main.go
|
||||
|
||||
run: build
|
||||
./build/${BINARY}
|
||||
@ -14,9 +16,15 @@ run: build
|
||||
admin: build
|
||||
./build/${ADMIN_BINARY} $(ARGS)
|
||||
|
||||
cli: build
|
||||
./build/${CLI_BINARY} $(ARGS)
|
||||
|
||||
dev:
|
||||
go run cmd/${BINARY}/main.go
|
||||
|
||||
cli-dev:
|
||||
go run cmd/${CLI_BINARY}/main.go $(ARGS)
|
||||
|
||||
clean:
|
||||
go clean ./...
|
||||
rm -rf build
|
||||
@ -24,4 +32,8 @@ clean:
|
||||
test:
|
||||
go test ./...
|
||||
|
||||
.PHONY: build run admin dev clean test
|
||||
install: build
|
||||
cp build/${CLI_BINARY} /usr/local/bin/tcman
|
||||
chmod +x /usr/local/bin/tcman
|
||||
|
||||
.PHONY: build run admin cli dev cli-dev clean test install
|
||||
|
||||
@ -7,38 +7,42 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
DatabaseURL string
|
||||
Port string
|
||||
StorageDir string
|
||||
MaxFileSize int64
|
||||
RateLimit float64
|
||||
CORSOrigins []string
|
||||
GzipLevel int
|
||||
MaxConnections int32
|
||||
MinConnections int32
|
||||
ConnLifetime time.Duration
|
||||
ConnIdleTime time.Duration
|
||||
HealthCheckPeriod time.Duration
|
||||
DefaultStorageLimit int64
|
||||
PricePerGBUSD float64
|
||||
DatabaseURL string
|
||||
Port string
|
||||
StorageDir string
|
||||
MaxFileSize int64
|
||||
RateLimit float64
|
||||
CORSOrigins []string
|
||||
GzipLevel int
|
||||
MaxConnections int32
|
||||
MinConnections int32
|
||||
ConnLifetime time.Duration
|
||||
ConnIdleTime time.Duration
|
||||
HealthCheckPeriod time.Duration
|
||||
DefaultStorageLimit int64
|
||||
PricePerGBUSD float64
|
||||
BitcoinMasterAddress string
|
||||
BitcoinNetwork string
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
return &Config{
|
||||
DatabaseURL: getEnv("DATABASE_URL", ""),
|
||||
Port: getEnv("PORT", "8080"),
|
||||
StorageDir: getEnv("STORAGE_DIR", "storage"),
|
||||
MaxFileSize: getEnvInt64("MAX_FILE_SIZE_MB", 100) * 1024 * 1024,
|
||||
RateLimit: getEnvFloat64("RATE_LIMIT", 20.0),
|
||||
CORSOrigins: getEnvSlice("CORS_ORIGINS", []string{"*"}),
|
||||
GzipLevel: getEnvInt("GZIP_LEVEL", 5),
|
||||
MaxConnections: getEnvInt32("DB_MAX_CONNECTIONS", 100),
|
||||
MinConnections: getEnvInt32("DB_MIN_CONNECTIONS", 10),
|
||||
ConnLifetime: getEnvDuration("DB_CONN_LIFETIME", time.Hour),
|
||||
ConnIdleTime: getEnvDuration("DB_CONN_IDLE_TIME", time.Minute),
|
||||
HealthCheckPeriod: getEnvDuration("DB_HEALTH_CHECK_PERIOD", 5*time.Second),
|
||||
DefaultStorageLimit: getEnvInt64("DEFAULT_STORAGE_LIMIT_GB", 1) * 1024 * 1024 * 1024,
|
||||
PricePerGBUSD: getEnvFloat64("PRICE_PER_GB_USD", 0.50),
|
||||
DatabaseURL: getEnv("DATABASE_URL", ""),
|
||||
Port: getEnv("PORT", "8080"),
|
||||
StorageDir: getEnv("STORAGE_DIR", "storage"),
|
||||
MaxFileSize: getEnvInt64("MAX_FILE_SIZE_MB", 100) * 1024 * 1024,
|
||||
RateLimit: getEnvFloat64("RATE_LIMIT", 20.0),
|
||||
CORSOrigins: getEnvSlice("CORS_ORIGINS", []string{"*"}),
|
||||
GzipLevel: getEnvInt("GZIP_LEVEL", 5),
|
||||
MaxConnections: getEnvInt32("DB_MAX_CONNECTIONS", 100),
|
||||
MinConnections: getEnvInt32("DB_MIN_CONNECTIONS", 10),
|
||||
ConnLifetime: getEnvDuration("DB_CONN_LIFETIME", time.Hour),
|
||||
ConnIdleTime: getEnvDuration("DB_CONN_IDLE_TIME", time.Minute),
|
||||
HealthCheckPeriod: getEnvDuration("DB_HEALTH_CHECK_PERIOD", 5*time.Second),
|
||||
DefaultStorageLimit: getEnvInt64("DEFAULT_STORAGE_LIMIT_GB", 1) * 1024 * 1024 * 1024,
|
||||
PricePerGBUSD: getEnvFloat64("PRICE_PER_GB_USD", 0.50),
|
||||
BitcoinMasterAddress: getEnv("BITCOIN_MASTER_ADDRESS", ""),
|
||||
BitcoinNetwork: getEnv("BITCOIN_NETWORK", "mainnet"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -55,8 +55,9 @@ type UsageRecord struct {
|
||||
}
|
||||
|
||||
type AccountService struct {
|
||||
pool *pgxpool.Pool
|
||||
pricePerGB float64
|
||||
pool *pgxpool.Pool
|
||||
pricePerGB float64
|
||||
bitcoinMasterAddr string
|
||||
}
|
||||
|
||||
func NewAccountService(pool *pgxpool.Pool, cfg *config.Config) *AccountService {
|
||||
@ -66,8 +67,9 @@ func NewAccountService(pool *pgxpool.Pool, cfg *config.Config) *AccountService {
|
||||
}
|
||||
|
||||
return &AccountService{
|
||||
pool: pool,
|
||||
pricePerGB: pricePerGB,
|
||||
pool: pool,
|
||||
pricePerGB: pricePerGB,
|
||||
bitcoinMasterAddr: cfg.BitcoinMasterAddress,
|
||||
}
|
||||
}
|
||||
|
||||
@ -422,6 +424,10 @@ func (s *AccountService) CheckResourceLimits(ctx context.Context, accountID int6
|
||||
}
|
||||
|
||||
func (s *AccountService) generateBTCAddress() string {
|
||||
if s.bitcoinMasterAddr != "" {
|
||||
return s.bitcoinMasterAddr
|
||||
}
|
||||
|
||||
bytes := make([]byte, 20)
|
||||
rand.Read(bytes)
|
||||
return fmt.Sprintf("bc1q%x", bytes)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user