Skip to content
Snippets Groups Projects
Verified Commit 29a54dc7 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

chore: commit save point

parent 39b83893
No related branches found
No related tags found
No related merge requests found
Showing
with 1174 additions and 92 deletions
# Created by https://www.toptal.com/developers/gitignore/api/intellij+iml,phpunit,git,vim,visualstudiocode,phpstorm,go,intellij+all,netbeans,dbeaver,node,yarn
# Edit at https://www.toptal.com/developers/gitignore?templates=intellij+iml,phpunit,git,vim,visualstudiocode,phpstorm,go,intellij+all,netbeans,dbeaver,node,yarn
### DBeaver ###
# ide config file
.dbeaver-data-sources*.xml
### Git ###
# Created by git for backups. To disable backups in Git:
# git config --global mergetool.keepBackup false
*.orig
# Created by git when using merge tools for conflicts
*.BACKUP.*
*.BASE.*
*.LOCAL.*
*.REMOTE.*
*_BACKUP_*.txt
*_BASE_*.txt
*_LOCAL_*.txt
*_REMOTE_*.txt
### Go ###
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work
### Go Patch ###
/vendor/
/Godeps/
### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### Intellij+all Patch ###
# Ignore everything but code style settings and run configurations
# that are supposed to be shared within teams.
.idea/*
!.idea/codeStyles
!.idea/runConfigurations
### Intellij+iml ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
# AWS User-specific
# Generated files
# Sensitive or high-churn files
# Gradle
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
# Mongo Explorer plugin
# File-based project format
# IntelliJ
# mpeltonen/sbt-idea plugin
# JIRA plugin
# Cursive Clojure plugin
# SonarLint plugin
# Crashlytics plugin (for Android Studio and IntelliJ)
# Editor-based Rest Client
# Android studio 3.1+ serialized cache file
### Intellij+iml Patch ###
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
*.iml
modules.xml
.idea/misc.xml
*.ipr
### NetBeans ###
**/nbproject/private/
**/nbproject/Makefile-*.mk
**/nbproject/Package-*.bash
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
### Node Patch ###
# Serverless Webpack directories
.webpack/
# Optional stylelint cache
# SvelteKit build / generate output
.svelte-kit
### PhpStorm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
# AWS User-specific
# Generated files
# Sensitive or high-churn files
# Gradle
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
# Mongo Explorer plugin
# File-based project format
# IntelliJ
# mpeltonen/sbt-idea plugin
# JIRA plugin
# Cursive Clojure plugin
# SonarLint plugin
# Crashlytics plugin (for Android Studio and IntelliJ)
# Editor-based Rest Client
# Android studio 3.1+ serialized cache file
### PhpStorm Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/
# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml
# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/
# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/ACHE_FILE
# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml
# Azure Toolkit for IntelliJ plugin
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
.idea/**/azureSettings.xml
### PHPUnit ###
# Covers PHPUnit
# Reference: https://phpunit.de/
# Generated files
.phpunit.result.cache
.phpunit.cache
# PHPUnit
/app/phpunit.xml
/phpunit.xml
# Build data
/build/
### Vim ###
# Swap
[._]*.s[a-v][a-z]
!*.svg # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Session
Session.vim
Sessionx.vim
# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
# Local History for Visual Studio Code
.history/
# Built Visual Studio Code Extensions
*.vsix
### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide
# Support for Project snippet scope
.vscode/*.code-snippets
# Ignore code-workspaces
*.code-workspace
### yarn ###
# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
.yarn/*
!.yarn/releases
!.yarn/patches
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
# if you are NOT using Zero-installs, then:
# comment the following lines
!.yarn/cache
# and uncomment the following lines
# .pnp.*
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="release print" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="conan" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="--config=development/examples/e1/config.yaml release print" />
<kind value="DIRECTORY" />
<directory value="$PROJECT_DIR$/application/source" />
<filePath value="$PROJECT_DIR$/application/source/main.go" />
<method v="2" />
</configuration>
</component>
\ No newline at end of file
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="server serve" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="conan" />
<working_directory value="$PROJECT_DIR$/development/examples/e1" />
<parameters value="--config=development/examples/e1/config.yaml server serve" />
<kind value="DIRECTORY" />
<directory value="$PROJECT_DIR$/application/source" />
<filePath value="$PROJECT_DIR$/application/source/main.go" />
<method v="2" />
</configuration>
</component>
\ No newline at end of file
Makefile 0 → 100644
#############################################################################################
#############################################################################################
##
## PROJECT-DEFINITIONS
##
#############################################################################################
#############################################################################################
COMPONENT_NAME := Monster
#############################################################################################
#############################################################################################
##
## MORE GENERAL BLOCK WITH STANDARD DEFINITIONS
##
#############################################################################################
#############################################################################################
# get Makefile directory name: http://stackoverflow.com/a/5982798/376773
THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
PROJECT_ROOT:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd)/
THIS_MAKEFILE:=$(PROJECT_ROOT)$(THIS_MAKEFILE_PATH)
-include $(PROJECT_ROOT)project.mk
## Define the location of Makefiles
MAKEFILE_IMPORT_PATH?=$(PROJECT_ROOT)makefiles/
-include $(MAKEFILE_IMPORT_PATH)project.mk
#############################################################################################
#############################################################################################
##
## INCLUSION OF VARIOUS STANDARD RULES
##
#############################################################################################
#############################################################################################
include $(MAKEFILE_IMPORT_PATH)directories-standard.mk
#include $(MAKEFILE_IMPORT_PATH)jsdoc.mk
include $(MAKEFILE_IMPORT_PATH)output.mk
include $(MAKEFILE_IMPORT_PATH)placeholder.mk
#include $(MAKEFILE_IMPORT_PATH)s3.mk
#include $(MAKEFILE_IMPORT_PATH)license-agpl3.mk
#include $(MAKEFILE_IMPORT_PATH)jsdoc-json.mk
#include $(MAKEFILE_IMPORT_PATH)go.mk
include $(MAKEFILE_IMPORT_PATH)gitignore.mk
include $(MAKEFILE_IMPORT_PATH)color.mk
include $(MAKEFILE_IMPORT_PATH)version.mk
#include $(MAKEFILE_IMPORT_PATH)node.mk
include $(MAKEFILE_IMPORT_PATH)terminal.mk
#include $(MAKEFILE_IMPORT_PATH)target-go-fetch-licenses.mk
#include $(MAKEFILE_IMPORT_PATH)target-deploy-tool.mk
#include $(MAKEFILE_IMPORT_PATH)target-jsdoc-build.mk
#include $(MAKEFILE_IMPORT_PATH)target-jekyll.mk
#include $(MAKEFILE_IMPORT_PATH)target-minerva.mk
#include $(MAKEFILE_IMPORT_PATH)target-docman.mk
#include $(MAKEFILE_IMPORT_PATH)target-node-build.mk
#include $(MAKEFILE_IMPORT_PATH)target-caddy.mk
include $(MAKEFILE_IMPORT_PATH)target-update-makefiles.mk
include $(MAKEFILE_IMPORT_PATH)target-help.mk
#include $(MAKEFILE_IMPORT_PATH)target-go-build.mk
#include $(MAKEFILE_IMPORT_PATH)target-node-test.mk
#include $(MAKEFILE_IMPORT_PATH)target-npm-publish.mk
include $(MAKEFILE_IMPORT_PATH)target-git.mk
include $(MAKEFILE_IMPORT_PATH)target-variable.mk
include $(MAKEFILE_IMPORT_PATH)terminal-check.mk
#############################################################################################
# Conan
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.schukai.com/oss/utilities/conan.git
git branch -M master
git push -uf origin master
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.schukai.com/oss/utilities/conan/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
package command
import (
"fmt"
"gitlab.schukai.com/oss/utilities/conan/release"
)
type ReleasePrintCommand struct {
}
func (r *ReleasePrintCommand) execute() {
fmt.Println("Mnemonic: ", release.GetMnemonic())
fmt.Println("Version: ", release.GetVersion())
fmt.Println("Build: ", release.GetBuild())
}
package command
type ReleaseCommand struct {
Print ReleasePrintCommand `command:"print" alias:"p" description:"Print release information"`
}
package command
import (
"gitlab.schukai.com/oss/utilities/conan/configuration"
"gitlab.schukai.com/oss/utilities/conan/logging"
"gitlab.schukai.com/oss/utilities/conan/server"
)
type ServerServeCommand struct {
Port string `long:"port" short:"p" description:"Port to listen on"`
Address string `long:"address" short:"a" description:"Address to serve on"`
WebPath string `long:"web-path" short:"w" description:"Path to web files"`
}
func (r *ServerServeCommand) execute() {
configuration.SetServerPort(r.Port)
configuration.SetServerAddress(r.Address)
configuration.SetServerWebPath(r.WebPath)
logging.InitLogger()
server.Start()
}
package command
type ServerCommand struct {
Serve ServerServeCommand `command:"serve" alias:"s" description:"Serve the application"`
}
package command
import "github.com/jessevdk/go-flags"
type CommandsStruct struct {
ConfigPath string `long:"config" short:"c" description:"Path to configuration file"`
Release ReleaseCommand `command:"release" alias:"r" description:"Release commands"`
Server ServerCommand `command:"server" alias:"s" description:"Start server and listen for requests"`
}
type commandsStruct struct {
parser *flags.Parser
definition *CommandsStruct
handler map[string]handler
}
var cmdInst *commandsStruct
func init() {
cmdInst = &commandsStruct{}
cmdInst.definition = &CommandsStruct{}
cmdInst.handler = make(map[string]handler)
registerCommandHandler("release-print", &cmdInst.definition.Release.Print)
registerCommandHandler("server-serve", &cmdInst.definition.Server.Serve)
}
func registerCommandHandler(name string, handler handler) {
cmdInst.handler[name] = handler
}
package command
import (
"github.com/jessevdk/go-flags"
"gitlab.schukai.com/oss/utilities/conan/configuration"
error2 "gitlab.schukai.com/oss/utilities/conan/error"
"gitlab.schukai.com/oss/utilities/conan/release"
)
func Execute() {
cmdInst.parser = flags.NewParser(cmdInst.definition, flags.Default)
_, err := cmdInst.parser.Parse()
if err != nil {
return
}
configuration.InitConfiguration(cmdInst.definition.ConfigPath, release.GetMnemonic())
c := cmdInst.parser.Command
if c == nil || c.Active == nil {
error2.PrintErrorAndExit("No command specified")
}
name := getActiveCommandName(c.Active, "")
if name == "" {
error2.PrintErrorAndExit("Unknown command: " + c.Name)
}
p, ok := cmdInst.handler[name]
if !ok {
error2.PrintErrorAndExit("No handler for command: " + name)
}
p.execute()
}
func getActiveCommandName(c *flags.Command, base string) string {
if c == nil {
return base
}
if c.Active != nil {
return getActiveCommandName(c.Active, c.Name)
}
if base != "" {
base = base + "-"
}
return base + c.Name
}
package command
type handler interface {
execute()
}
package configuration
type Settings map[string]interface{}
type ClientAddress *Client
type Client struct {
Endpoints struct {
Messages string `env:"CLIENT_ENDPOINT_MESSAGES,default=/messages" yaml:"Messages" json:"Messages"`
} `yaml:"Endpoints" json:"Endpoints"`
Settings `yaml:"Settings" json:"Settings"`
}
type Watch struct {
Path string `yaml:"Path" json:"Path"`
Command string `yaml:"Command" json:"Command"`
Exclude []string `yaml:"Exclude" json:"Exclude"`
}
type ConfigStruct struct {
Server struct {
Address string `env:"SERVER_ADDRESS" yaml:"Address"`
Host string `env:"SERVER_HOST" yaml:"Host"`
Port int `env:"SERVER_PORT,default=8080" yaml:"Port"`
Path struct {
Web string `env:"SERVER_PATH_WEB,default=web/" yaml:"Web"`
Source string `env:"SERVER_PATH_SOURCE,default=source/" yaml:"Source"`
Resource string `env:"SERVER_PATH_RESOURCE" yaml:"Resource"`
} `yaml:"Path"`
Logging struct {
Level string `env:"SERVER_LOGGING_LEVEL,default=info" yaml:"Level"`
}
Flags struct {
Debug bool `env:"SERVER_FLAGS_DEBUG,default=false" yaml:"Debug"`
FollowSymlinks bool `env:"SERVER_FLAGS_FOLLOW_SYMLINKS,default=false" yaml:"FollowSymlinks"`
} `yaml:"Flags"`
Watch []Watch `yaml:"Watch"`
} `yaml:"Server"`
Client Client `yaml:"Client" json:"Client"`
}
package configuration
import (
error2 "gitlab.schukai.com/oss/utilities/conan/error"
"net/url"
"strconv"
)
func GetConfigurationPath() string {
return configurationPath
}
func GetWatch() []Watch {
return configurationInstance.Server.Watch
}
func GetServerFlagFollowSymlinks() bool {
return configurationInstance.Server.Flags.FollowSymlinks
}
func GetServerLoglevel() string {
return configurationInstance.Server.Logging.Level
}
func GetClientMessagesEndpointPath() string {
u, err := url.ParseRequestURI(configurationInstance.Client.Endpoints.Messages)
error2.CheckError(err)
return u.Path
}
func GetClientMessagesEndpoint() string {
return configurationInstance.Client.Endpoints.Messages
}
func SetServerPort(port string) {
if port == "" {
return
}
p, err := strconv.Atoi(port)
error2.CheckError(err)
configurationInstance.Server.Port = p
}
func SetServerHost(host string) {
if host == "" {
return
}
configurationInstance.Server.Host = host
}
func SetServerAddress(address string) {
if address == "" {
return
}
configurationInstance.Server.Address = address
}
func SetServerWebPath(path string) {
if path == "" {
return
}
configurationInstance.Server.Path.Web = path
}
func GetServerPort() string {
return strconv.FormatInt(int64(configurationInstance.Server.Port), 10)
}
func GetServerAddress() string {
return configurationInstance.Server.Address
}
func GetServerHost() string {
return configurationInstance.Server.Host
}
func GetServerWebPath() string {
return getAbsolutePath(configurationInstance.Server.Path.Web)
}
func GetServerSourcePath() string {
return getAbsolutePath(configurationInstance.Server.Path.Source)
}
func IsResourcePathSet() bool {
return configurationInstance.Server.Path.Resource != ""
}
func GetResourcePath() string {
return getAbsolutePath(configurationInstance.Server.Path.Resource)
}
package configuration
import (
"context"
envconfig "github.com/sethvargo/go-envconfig"
"gitlab.schukai.com/oss/utilities/conan/constants"
error2 "gitlab.schukai.com/oss/utilities/conan/error"
"gitlab.schukai.com/oss/utilities/conan/logging"
"gopkg.in/yaml.v3"
"os"
"os/user"
"path"
"strings"
)
var configurationInstance *ConfigStruct
var configurationPath string
func init() {
configurationInstance = &ConfigStruct{}
configurationInstance.Client = NewClient()
}
func NewClient() Client {
c := Client{}
c.Settings = Settings{}
return c
}
func GetConfiguration() *ConfigStruct {
return configurationInstance
}
func GetDefaultClientConfiguration() Client {
return configurationInstance.Client
}
func InitConfiguration(cfgPath, mnemonic string) {
userConfig := ""
usr, err := user.Current()
if err == nil {
userConfig = path.Join(usr.HomeDir, ".config", mnemonic, constants.ConfigFileName)
}
var currentConfigPath string
current, err := os.Getwd()
if err == nil {
currentConfigPath = path.Join(current, constants.ConfigFileName)
}
etcConfigPath := path.Join("/etc", mnemonic, constants.ConfigFileName)
if cfgPath != "" && !path.IsAbs(cfgPath) {
cfgPath = path.Join(current, cfgPath)
}
ctx := context.Background()
l := envconfig.PrefixLookuper(strings.ReplaceAll(strings.ToUpper(mnemonic), "-", "_")+"_", envconfig.OsLookuper())
err = envconfig.ProcessWith(ctx, configurationInstance, l)
error2.CheckError(err)
for _, p := range []string{
cfgPath,
currentConfigPath,
userConfig,
etcConfigPath} {
if checkAndInitConfiguration(p, configurationInstance) {
configurationPath = path.Dir(p)
break
}
}
sanitize()
}
func Reload() {
logging.LogInfo("Reloading configuration")
checkAndInitConfiguration(path.Join(configurationPath, constants.ConfigFileName), configurationInstance)
}
func checkAndInitConfiguration(name string, config *ConfigStruct) bool {
if name == "" {
return false
}
ptr, err := os.Open(name)
if err != nil {
return false
}
defer ptr.Close()
decoder := yaml.NewDecoder(ptr)
err = decoder.Decode(config)
if err != nil {
return false
}
return true
}
package configuration
import (
error2 "gitlab.schukai.com/oss/utilities/conan/error"
"net/url"
"path"
"strconv"
)
func sanitizeMessageEndpoint() {
e := configurationInstance.Client.Endpoints.Messages
u, err := url.ParseRequestURI(e)
error2.CheckError(err)
if u.Scheme != "ws" {
u.Scheme = "ws"
}
if u.Host == "" {
u.Host = configurationInstance.Server.Host
if u.Host == "" {
error2.PrintErrorAndExit("Host not set")
}
}
configurationInstance.Client.Endpoints.Messages = u.String()
}
func sanitizeSerer() {
if configurationInstance.Server.Address == "localhost" {
configurationInstance.Server.Address = "127.0.0.1"
}
if configurationInstance.Server.Port == 0 {
configurationInstance.Server.Port = 8080
}
if configurationInstance.Server.Host == "" {
configurationInstance.Server.Host = "127.0.0.1:" + strconv.Itoa(configurationInstance.Server.Port)
}
}
func sanitizeWatch() {
for i := range configurationInstance.Server.Watch {
if configurationInstance.Server.Watch[i].Path == "." {
configurationInstance.Server.Watch[i].Path = GetConfigurationPath()
continue
}
if configurationInstance.Server.Watch[i].Path == "" {
continue
}
if !path.IsAbs(configurationInstance.Server.Watch[i].Path) {
configurationInstance.Server.Watch[i].Path = path.Join(GetConfigurationPath(), configurationInstance.Server.Watch[i].Path)
}
}
}
func sanitize() {
sanitizeSerer()
sanitizeWatch()
sanitizeMessageEndpoint()
}
package configuration
import (
error2 "gitlab.schukai.com/oss/utilities/conan/error"
"os"
"path"
)
func getAbsolutePath(sub string) string {
if path.IsAbs(sub) {
return sub
}
if configurationPath != "" {
return path.Clean(path.Join(configurationPath, sub))
}
p, err := os.Getwd()
error2.CheckError(err)
return path.Clean(path.Join(p, sub))
}
package constants
const ConfigFileName = "config.yaml"
const WebManifestName = "app.webmanifest"
const FaviconName = "favicon.ico"
const AssetsPath = "assets"
const AppStyleDirectory = "styles"
const AppScriptDirectory = "scripts"
const StandardCacheControl = "no-cache, no-store, must-revalidate"
package error
import (
"github.com/gookit/color"
"os"
)
func CheckError(err error) {
if err != nil {
PrintErrorAndExit(err.Error())
}
}
func Exit(code int) {
os.Exit(code)
}
var lastBlock string
func PrintErrorAndExit(message string, a ...interface{}) {
PrintError(message, a...)
os.Exit(1)
}
func PrintError(message string, a ...interface{}) {
if lastBlock == "error" {
color.Error.Println("\t"+message, a)
return
}
lastBlock = "error"
color.Error.Block(message, a...)
}
func PrintWarning(message string, a ...interface{}) {
if lastBlock == "warning" {
color.Warn.Println("\t"+message, a)
return
}
lastBlock = "warning"
color.Warn.Block(message, a...)
}
package error
import (
"errors"
)
var (
// ErrNotFound is the error returned when a resource is not found.
ErrNotFound = errors.New("not found")
// ErrAlreadyExists is the error returned when a resource already exists.
ErrAlreadyExists = errors.New("already exists")
// ErrInvalidArgument is the error returned when an invalid argument is provided.
ErrInvalidArgument = errors.New("invalid argument")
// ErrInvalidState is the error returned when an operation is not allowed in the current state.
ErrInvalidState = errors.New("invalid state")
// ErrNotImplemented is the error returned when an operation is not implemented.
ErrNotImplemented = errors.New("not implemented")
// ErrTimeout is the error returned when an operation times out.
ErrTimeout = errors.New("timeout")
// ErrCanceled is the error returned when an operation is canceled.
ErrCanceled = errors.New("canceled")
// ErrUnauthorized is the error returned when an operation is unauthorized.
ErrUnauthorized = errors.New("unauthorized")
// ErrForbidden is the error returned when an operation is forbidden.
ErrForbidden = errors.New("forbidden")
// ErrFailedPrecondition is the error returned when an operation failed precondition.
ErrFailedPrecondition = errors.New("failed precondition")
// ErrAborted is the error returned when an operation is aborted.
ErrAborted = errors.New("aborted")
// ErrOutOfRange is the error returned when an operation is out of range.
ErrOutOfRange = errors.New("out of range")
// ErrUnavailable is the error returned when an operation is unavailable.
ErrUnavailable = errors.New("unavailable")
// ErrDataLoss is the error returned when data is lost.
ErrDataLoss = errors.New("data loss")
// ErrUnauthenticated is the error returned when an operation is unauthenticated.
ErrUnauthenticated = errors.New("unauthenticated")
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment