fiumba
This commit is contained in:
5
src/app/mode/mode.go
Normal file
5
src/app/mode/mode.go
Normal file
@ -0,0 +1,5 @@
|
||||
// Package mode indicates application modes, it has variables to indicate special settings.
|
||||
package mode
|
||||
|
||||
// Debug indicates if debug mode is enabled, so for example we can log debug info.
|
||||
var Debug bool //nolint
|
||||
122
src/app/model.go
Normal file
122
src/app/model.go
Normal file
@ -0,0 +1,122 @@
|
||||
// Package app defines all app models
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/shopspring/decimal"
|
||||
|
||||
"quantex.com.ar/multidb"
|
||||
notifyall "quantex.com/qfixdpl/src/client/notify/all"
|
||||
)
|
||||
|
||||
//revive:disable:max-public-structs // This is a file containing app public models
|
||||
|
||||
type Config struct {
|
||||
Global
|
||||
Service
|
||||
}
|
||||
|
||||
type Global struct {
|
||||
GitUser string
|
||||
GitPass string
|
||||
CertEncryptionKey string
|
||||
Async Async `toml:"MQTT"`
|
||||
MultiDB multidb.Config
|
||||
AllowedOrigins []string
|
||||
ExchangeRateAPIKey string
|
||||
RatingStartDate string
|
||||
ScreenshotFolder string
|
||||
QApixPort string
|
||||
QApixHost string // Optional
|
||||
Notify notifyall.Config
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
QApixToken string // TODO find a better way to authenticate
|
||||
External map[string]ExtAuth `toml:"External"`
|
||||
AuthorizedServices map[string]AuthorizedService `toml:"AuthorizedServices"`
|
||||
APIBasePort string
|
||||
EnableJWTAuth bool // Enable JWT authentication for service-to-service communication
|
||||
}
|
||||
|
||||
type ExtAuth struct {
|
||||
Host string
|
||||
Port string
|
||||
Name string
|
||||
Token string
|
||||
}
|
||||
|
||||
type AuthorizedService struct {
|
||||
Name string
|
||||
Permissions []ServicePermission
|
||||
Token *string
|
||||
}
|
||||
|
||||
func (s *AuthorizedService) HasPermissions(requiredPerm ServicePermission) bool {
|
||||
for _, perm := range s.Permissions {
|
||||
if perm == requiredPerm || perm == ServicePermissionFullAccess {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
type Async struct {
|
||||
Protocol string
|
||||
URL string
|
||||
Subdomain string
|
||||
Secret string
|
||||
}
|
||||
|
||||
type TargetParty struct {
|
||||
Party Entity
|
||||
Favorite bool
|
||||
Selected bool
|
||||
}
|
||||
|
||||
type Entity struct {
|
||||
ID string
|
||||
Name string
|
||||
}
|
||||
|
||||
type InstID string
|
||||
|
||||
type User struct {
|
||||
UserID string
|
||||
Token string
|
||||
Name string
|
||||
LastName string
|
||||
Password string
|
||||
Email string
|
||||
Phone string
|
||||
Sender Entity
|
||||
Party Entity
|
||||
BannedParties []Entity
|
||||
TargetParties []TargetParty
|
||||
Subscriptions []InstID
|
||||
IsMiddleman bool
|
||||
IsSuperUser bool
|
||||
IsBackOffice bool
|
||||
IsTrader bool
|
||||
IsService bool
|
||||
IsPartyAdmin bool
|
||||
IsViewer bool
|
||||
IsTesting bool
|
||||
AllowTokenAuth bool
|
||||
Rating decimal.Decimal
|
||||
}
|
||||
|
||||
type UserDataProvider interface {
|
||||
GetUserByEmail(email string) User
|
||||
}
|
||||
|
||||
//go:generate go-enum -f=$GOFILE --lower --marshal
|
||||
|
||||
// Service Permissions
|
||||
// ENUM(
|
||||
// ReadOnly
|
||||
// ReadWrite
|
||||
// FullAccess
|
||||
// Undefined
|
||||
// )
|
||||
type ServicePermission int //nolint:recvcheck // The methods of this are autogenerated
|
||||
118
src/app/version/version.go
Normal file
118
src/app/version/version.go
Normal file
@ -0,0 +1,118 @@
|
||||
// Package version defines current build app information
|
||||
package version
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:generate go-enum -f=$GOFILE --lower --marshal
|
||||
|
||||
// AppName stores the Application Name
|
||||
const (
|
||||
AppName = "qfixdpl"
|
||||
poweredBy = "Powered by Quantex Technologies"
|
||||
quantexEnvironment = "QUANTEX_ENVIRONMENT"
|
||||
)
|
||||
|
||||
var (
|
||||
// See tools/build.sh script to see how these variables are set
|
||||
versionBase = "0.1" //nolint:gochecknoglobals // Should be global cos this is set on the build with version info
|
||||
buildHash string //nolint:gochecknoglobals // Idem
|
||||
buildBranch string //nolint:gochecknoglobals // Idem
|
||||
builtTime string //nolint:gochecknoglobals // Idem
|
||||
hostname string //nolint:gochecknoglobals // Idem
|
||||
)
|
||||
|
||||
// EnvironmentType environments
|
||||
// ENUM(
|
||||
// prod
|
||||
// open-demo
|
||||
// demo
|
||||
// dev
|
||||
// )
|
||||
type EnvironmentType int //nolint:recvcheck // The methods of this are autogenerated
|
||||
|
||||
var environment EnvironmentType //nolint:gochecknoglobals // Just keept this global to avoid having to create an instance
|
||||
|
||||
func init() {
|
||||
aux := os.Getenv(quantexEnvironment)
|
||||
if aux == "" {
|
||||
panic("QUANTEX_ENVIRONMENT is not set")
|
||||
}
|
||||
|
||||
env, err := ParseEnvironmentType(aux)
|
||||
if err != nil {
|
||||
panic("Invalid QUANTEX_ENVIRONMENT value: " + aux + " " + err.Error())
|
||||
}
|
||||
|
||||
environment = env
|
||||
}
|
||||
|
||||
// Base returns the version base name
|
||||
func Base() string {
|
||||
return versionBase
|
||||
}
|
||||
|
||||
// BuildHash returns the build hash
|
||||
func BuildHash() string {
|
||||
return buildHash
|
||||
}
|
||||
|
||||
// BuildBranch returns the build branch
|
||||
func BuildBranch() string {
|
||||
return buildBranch
|
||||
}
|
||||
|
||||
// Hostname returns the build time
|
||||
func Hostname() string {
|
||||
return hostname
|
||||
}
|
||||
|
||||
// Name returns the version name
|
||||
func Name() string {
|
||||
bh := buildHash
|
||||
if len(buildHash) >= 8 {
|
||||
bh = buildHash[0:8]
|
||||
}
|
||||
|
||||
return versionBase + "-" + bh
|
||||
}
|
||||
|
||||
// BuiltTime returns the build time
|
||||
func BuiltTime() string {
|
||||
return builtTime
|
||||
}
|
||||
|
||||
// Environment returns service environment
|
||||
func Environment() EnvironmentType {
|
||||
return environment
|
||||
}
|
||||
|
||||
// Environment returns service environment
|
||||
func BuildFullInfo() string {
|
||||
bt := strings.Replace(builtTime, "-", " ", -1)
|
||||
bh := buildHash
|
||||
|
||||
if len(buildHash) >= 8 {
|
||||
bh = buildHash[0:8]
|
||||
}
|
||||
|
||||
return fmt.Sprintf("v%s-%s-%s, built on %s ", versionBase, buildBranch, bh, bt)
|
||||
}
|
||||
|
||||
// Info returns the complete version information
|
||||
func Info() string {
|
||||
sb := strings.Builder{}
|
||||
// revive:disable No need to handle errors here
|
||||
sb.WriteString(fmt.Sprintf("v%s \n", versionBase))
|
||||
sb.WriteString(fmt.Sprintln(" Build ", BuildFullInfo()))
|
||||
sb.WriteString(fmt.Sprintln(" ", poweredBy, ""))
|
||||
sb.WriteString(fmt.Sprintf(" Go %s \n", runtime.Version()))
|
||||
sb.WriteString(fmt.Sprintf(" Environment %s \n", environment))
|
||||
sb.WriteString(fmt.Sprintf(" Built from %s \n", hostname))
|
||||
// revive:enable
|
||||
return sb.String()
|
||||
}
|
||||
Reference in New Issue
Block a user