diff --git a/.idea/runConfigurations/server_serve.xml b/.idea/runConfigurations/server_serve.xml index 33ef7dfb01c4cbe3fb64a733d711f0dae9b2d893..ee169b50bd977c19674880b221660237a6724fb5 100644 --- a/.idea/runConfigurations/server_serve.xml +++ b/.idea/runConfigurations/server_serve.xml @@ -2,7 +2,7 @@ <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 --pid-file=/tmp/conan.pid" /> + <parameters value="--config=config.yaml server serve " /> <kind value="DIRECTORY" /> <directory value="$PROJECT_DIR$/application/source" /> <filePath value="$PROJECT_DIR$/application/source/main.go" /> diff --git a/Makefile b/Makefile index cabdd499aee77dd96c141234307901dcc5b81cab..7ce8147cd30dd43d56d58f4755177b31bd988276 100644 --- a/Makefile +++ b/Makefile @@ -58,6 +58,7 @@ include $(MAKEFILE_IMPORT_PATH)target-deploy-tool.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-conan.mk include $(MAKEFILE_IMPORT_PATH)target-update-makefiles.mk include $(MAKEFILE_IMPORT_PATH)target-help.mk include $(MAKEFILE_IMPORT_PATH)target-go-build.mk diff --git a/Makefile.example b/Makefile.example index c9d8453ecd167bfc2ce8bad811a1ab3a110fb302..ffbe88952ded52768d8e13635f0787be61926057 100644 --- a/Makefile.example +++ b/Makefile.example @@ -58,6 +58,7 @@ include $(MAKEFILE_IMPORT_PATH)terminal.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-conan.mk include $(MAKEFILE_IMPORT_PATH)target-update-makefiles.mk include $(MAKEFILE_IMPORT_PATH)target-help.mk #include $(MAKEFILE_IMPORT_PATH)target-go-build.mk diff --git a/application/source/command/cmd-server-serve.go b/application/source/command/cmd-server-serve.go index 24d642c4822efdbe978826459cf42b161d1ec9db..eb70932da0649ce8e865f0d514bfa2c877a8e1fa 100644 --- a/application/source/command/cmd-server-serve.go +++ b/application/source/command/cmd-server-serve.go @@ -1,7 +1,6 @@ package command import ( - "fmt" "gitlab.schukai.com/oss/utilities/conan/configuration" "gitlab.schukai.com/oss/utilities/conan/logging" "gitlab.schukai.com/oss/utilities/conan/server" @@ -25,8 +24,6 @@ func (r *ServerServeCommand) execute() { configuration.SetServerAddress(r.Address) configuration.SetServerWebPath(r.WebPath) - fmt.Printf("Serving on %s:%s\n", r.WatchPath, r.Exclude) - var w string if r.WatchPath != "" { w = r.WatchPath diff --git a/application/source/configuration/definition.go b/application/source/configuration/definition.go index 679754b96cc32e87d2e527d57f9db1573e433676..a3e15d5058f884642c7d5913b470734879231002 100644 --- a/application/source/configuration/definition.go +++ b/application/source/configuration/definition.go @@ -2,15 +2,6 @@ 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"` diff --git a/application/source/configuration/getter-setter.go b/application/source/configuration/getter-setter.go index 39a87a2bb95c313c5dbd19684549fea0a26a4287..e13658942934a9a3e20010bd0971d50f52c62694 100644 --- a/application/source/configuration/getter-setter.go +++ b/application/source/configuration/getter-setter.go @@ -21,17 +21,6 @@ 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 == "" { diff --git a/application/source/configuration/init.go b/application/source/configuration/init.go index 2543214b3f0a27d3f4bb2cfd8fe12ec708ef7af2..9597242676dbf373b7f503c5d4abc776e06f7127 100644 --- a/application/source/configuration/init.go +++ b/application/source/configuration/init.go @@ -18,24 +18,8 @@ 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 := "" @@ -54,10 +38,18 @@ func InitConfiguration(cfgPath, mnemonic string) { etcConfigPath := path.Join("/etc", mnemonic, constants.ConfigFileName) - if cfgPath != "" && !path.IsAbs(cfgPath) { - cfgPath = path.Join(current, cfgPath) - } + if cfgPath != "" { + if !path.IsAbs(cfgPath) { + cfgPath = path.Join(current, cfgPath) + } + + if _, err := os.Stat(cfgPath); os.IsNotExist(err) { + error2.PrintErrorAndExit("Configuration file not found: " + cfgPath) + } + + } + ctx := context.Background() l := envconfig.PrefixLookuper(strings.ReplaceAll(strings.ToUpper(mnemonic), "-", "_")+"_", envconfig.OsLookuper()) diff --git a/application/source/configuration/sanitize.go b/application/source/configuration/sanitize.go index 81e68e5fb26a12e4adcb3509b6ea9469197ebeaf..9d8470af38851c4153cf8661bfdf1ca2cbd82759 100644 --- a/application/source/configuration/sanitize.go +++ b/application/source/configuration/sanitize.go @@ -5,28 +5,6 @@ import ( "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" { @@ -63,5 +41,4 @@ func sanitizeWatch() { func sanitize() { sanitizeSerer() sanitizeWatch() - //sanitizeMessageEndpoint() } diff --git a/application/source/logging/logger.go b/application/source/logging/logger.go index ed3aa0db116416c1426211d57205df25f6ee065a..b45bfe2a819c8f21de9fe2ed254e7e9bf5189576 100644 --- a/application/source/logging/logger.go +++ b/application/source/logging/logger.go @@ -3,6 +3,7 @@ package logging import ( "github.com/go-chi/chi/v5/middleware" "gitlab.schukai.com/oss/utilities/conan/header" + "gitlab.schukai.com/oss/utilities/conan/release" "go.uber.org/zap" "go.uber.org/zap/zapcore" "net/http" @@ -14,15 +15,60 @@ var sugaredLogger *zap.SugaredLogger func InitLogger() { - if logger != nil && sugaredLogger != nil { - return + var cfg zap.Config + + if release.GetVersion() == "dev" { + cfg.Development = true + } else { + cfg.Development = false } - var mode string + cfg.Encoding = "console" + cfg.OutputPaths = []string{"stdout"} + cfg.ErrorOutputPaths = []string{"stderr"} + cfg.EncoderConfig = zap.NewDevelopmentEncoderConfig() + + l := zapcore.Level(10) + l = zap.InfoLevel + + switch l { + // DebugLevel logs are typically voluminous, and are usually disabled in + // production. + case zap.DebugLevel: + cfg.Level = zap.NewAtomicLevelAt(zap.DebugLevel) + // InfoLevel is the default logging priority. + case zap.InfoLevel: + cfg.Level = zap.NewAtomicLevelAt(zap.InfoLevel) + // WarnLevel logs are more important than Info, but don't need individual + // human review. + case zap.WarnLevel: + cfg.Level = zap.NewAtomicLevelAt(zap.WarnLevel) + // ErrorLevel logs are high-priority. If an application is running smoothly, + // it shouldn't generate any error-level logs. + case zap.ErrorLevel: + cfg.Level = zap.NewAtomicLevelAt(zap.ErrorLevel) + // DPanicLevel logs are particularly important errors. In development the + // logger panics after writing the message. + case zap.DPanicLevel: + cfg.Level = zap.NewAtomicLevelAt(zap.DPanicLevel) + // PanicLevel logs a message, then panics. + case zap.PanicLevel: + cfg.Level = zap.NewAtomicLevelAt(zap.PanicLevel) + // FatalLevel logs a message, then calls os.Exit(1). + case zap.FatalLevel: + cfg.Level = zap.NewAtomicLevelAt(zap.FatalLevel) + default: + cfg.Level = zap.NewAtomicLevelAt(zap.ErrorLevel) + + } - logger, _ = zap.NewDevelopment() + logger, err := cfg.Build() + if err != nil { + panic(err) + } + defer logger.Sync() - defer logger.Sync() // flushes buffer, if any + var mode string sugaredLogger = logger.Sugar() sugaredLogger.Infof("init %s logger", mode) diff --git a/application/source/watch/resources.go b/application/source/watch/resources.go index 340b476b28e94f4e27befc971824752dc5691f0d..12cc6b1237f993ecdf3778e2ae6d5233e4030a5c 100644 --- a/application/source/watch/resources.go +++ b/application/source/watch/resources.go @@ -67,7 +67,7 @@ func executeWatchAction(watchPath string) { } if w.Command == "" { - logging.LogInfo("watching: no command defined for %s", watchPath) + logging.LogDebug("watching: no command defined for %s", watchPath) websocket.SendReloadMessage() continue } @@ -274,7 +274,7 @@ func addToWatchlist(p string) { if err != nil { logging.LogError("watching: watch error: %v", err.Error()) } else { - logging.LogInfo("watching: watching %s", p) + logging.LogDebug("watching: watching %s", p) watchList[p] = p } diff --git a/deployment/vendor/conan/conan b/deployment/vendor/conan/conan new file mode 100755 index 0000000000000000000000000000000000000000..fa98c2dfb8e092e8e29fc76c0312dbd11a9ee4a7 Binary files /dev/null and b/deployment/vendor/conan/conan differ diff --git a/development/makefile/target-conan.mk b/development/makefile/target-conan.mk new file mode 100644 index 0000000000000000000000000000000000000000..3f50af7c3ebe69bb62418dd9725749bdd54d3dc5 --- /dev/null +++ b/development/makefile/target-conan.mk @@ -0,0 +1,21 @@ +############################################################################################# +############################################################################################# +## +## SERVER CONAN +## +############################################################################################# +############################################################################################# + +CONAN_BIN ?= $(VENDOR_PATH)conan +CONAN_CONFIG ?= $(VENDOR_PATH)conan.conf + +$(CONAN_BIN): + $(QUIET) $(MKDIR) -p $(VENDOR_PATH) + $(QUIET) $(WGET) -O $(CONAN_BIN) http://download.schukai.com/tools/conan/conan-$(shell uname -s | tr [:upper:] [:lower:])-$(shell echo `uname -m | sed s/aarch64/arm64/ | sed s/x86_64/amd64/`) + $(QUIET) $(CHMOD) u+x $(CONAN_BIN) + +.PHONY: run-conan +## run conan webserver +run-conan: $(CONAN_BIN) + $(QUIET) $(CONAN_BIN) server serve --config $(CONAN_CONFIG) + diff --git a/release.json b/release.json index 66788cb595ac79960aab21b54aaab64ecb1b0992..61d897fde5a4046000005e17dfbb922970d12212 100644 --- a/release.json +++ b/release.json @@ -1 +1 @@ -{"version":"0.1.38"} +{"version":"0.1.39"}