Add monorepo structure for NexaVPN WireGuard control plane including: - .gitignore for node_modules, build artifacts, and environment files - README with project overview, monorepo layout, and quick start guide - Admin web UI with React, Vite, TypeScript, and nginx reverse proxy - API client with type definitions for users, devices, policies, gateways, and audit logs - Admin pages for dashboard, users, devices, policies, g
83 lines
2.1 KiB
Go
83 lines
2.1 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
type Config struct {
|
|
AppName string
|
|
Environment string
|
|
HTTPAddress string
|
|
DatabaseURL string
|
|
JWTIssuer string
|
|
JWTSecret string
|
|
AccessTokenTTL time.Duration
|
|
RefreshTokenTTL time.Duration
|
|
DefaultGatewayID string
|
|
DefaultDNS []string
|
|
DefaultVPNCIDR string
|
|
DefaultGatewayHost string
|
|
DefaultGatewayPubKey string
|
|
}
|
|
|
|
func Load() Config {
|
|
return Config{
|
|
AppName: getenv("APP_NAME", "NexaVPN"),
|
|
Environment: getenv("APP_ENV", "development"),
|
|
HTTPAddress: getenv("HTTP_ADDRESS", ":8080"),
|
|
DatabaseURL: getenv("DATABASE_URL", "postgres://nexavpn:nexavpn@localhost:5432/nexavpn?sslmode=disable"),
|
|
JWTIssuer: getenv("JWT_ISSUER", "nexavpn"),
|
|
JWTSecret: getenv("JWT_SECRET", "change-me-in-production"),
|
|
AccessTokenTTL: time.Duration(getenvInt("ACCESS_TOKEN_TTL_SECONDS", 900)) * time.Second,
|
|
RefreshTokenTTL: time.Duration(getenvInt("REFRESH_TOKEN_TTL_SECONDS", 2592000)) * time.Second,
|
|
DefaultGatewayID: getenv("DEFAULT_GATEWAY_ID", ""),
|
|
DefaultDNS: splitCSV(getenv("DEFAULT_DNS_SERVERS", "10.20.0.53")),
|
|
DefaultVPNCIDR: getenv("DEFAULT_VPN_CIDR", "100.96.0.0/24"),
|
|
DefaultGatewayHost: getenv("DEFAULT_GATEWAY_ENDPOINT", "vpn.example.com:51820"),
|
|
DefaultGatewayPubKey: getenv("DEFAULT_GATEWAY_PUBLIC_KEY", "replace-me"),
|
|
}
|
|
}
|
|
|
|
func getenv(key, fallback string) string {
|
|
if value := os.Getenv(key); value != "" {
|
|
return value
|
|
}
|
|
|
|
return fallback
|
|
}
|
|
|
|
func getenvInt(key string, fallback int) int {
|
|
if value := os.Getenv(key); value != "" {
|
|
parsed, err := strconv.Atoi(value)
|
|
if err == nil {
|
|
return parsed
|
|
}
|
|
}
|
|
|
|
return fallback
|
|
}
|
|
|
|
func splitCSV(value string) []string {
|
|
if value == "" {
|
|
return nil
|
|
}
|
|
|
|
var items []string
|
|
start := 0
|
|
for i := range value {
|
|
if value[i] == ',' {
|
|
if start < i {
|
|
items = append(items, value[start:i])
|
|
}
|
|
start = i + 1
|
|
}
|
|
}
|
|
if start < len(value) {
|
|
items = append(items, value[start:])
|
|
}
|
|
|
|
return items
|
|
}
|