Best Gauge code snippet using install.getMessage
admin.go
Source:admin.go
1package service2import (3 "fmt"4 "net/http"5 "os"6 "path"7 "sort"8 "strings"9 "text/template"10 db "github.com/nervatura/nervatura/service/pkg/database"11 nt "github.com/nervatura/nervatura/service/pkg/nervatura"12 ut "github.com/nervatura/nervatura/service/pkg/utils"13)14// AdminService implements the Nervatura Admin GUI15type AdminService struct {16 Config map[string]interface{}17 GetNervaStore func(database string) *nt.NervaStore18 templates *template.Template19 GetTokenKeys func() map[string]map[string]string20}21func (adm *AdminService) LoadTemplates() {22 adm.templates, _ = template.ParseFS(ut.Static, path.Join("static", "views", "*.html"))23}24// template rendering25func (adm *AdminService) render(w http.ResponseWriter, template string, data interface{}) {26 w.Header().Set("Content-Type", "text/html; charset=utf-8")27 if err := adm.templates.ExecuteTemplate(w, template, data); err != nil {28 http.Error(w, ut.GetMessage("error_internal"), http.StatusInternalServerError)29 }30}31func (adm *AdminService) parseData(r *http.Request) nt.IM {32 return nt.IM{33 "version": adm.Config["version"], "view_version": ut.GetMessage("view_version"),34 "theme": r.PostFormValue("theme"), "menu": r.PostFormValue("menu"),35 "token": r.PostFormValue("token"),36 "database": r.PostFormValue("database"), "demo": r.PostFormValue("demo"),37 "apikey": r.PostFormValue("apikey"),38 "username": r.PostFormValue("username"), "password": r.PostFormValue("password"),39 "confirm": r.PostFormValue("confirm"), "reportkey": r.PostFormValue("reportkey"),40 "errors": nt.SM{}, "result": []nt.SM{},41 "view_admin": ut.GetMessage("view_admin"),42 "view_database": ut.GetMessage("view_database"), "view_client": ut.GetMessage("view_client"),43 "view_docs": ut.GetMessage("view_docs"), "view_theme": ut.GetMessage("view_theme"),44 "view_login": ut.GetMessage("view_login"), "view_submit": ut.GetMessage("view_submit"),45 "view_username": ut.GetMessage("view_username"), "view_password": ut.GetMessage("view_password"),46 "view_create": ut.GetMessage("view_create"), "view_api_key": ut.GetMessage("view_api_key"),47 "view_alias": ut.GetMessage("view_alias"), "view_demo": ut.GetMessage("view_demo"),48 "view_logout": ut.GetMessage("view_logout"), "view_token": ut.GetMessage("view_token"),49 "view_refresh": ut.GetMessage("view_refresh"), "view_password_change": ut.GetMessage("view_password_change"),50 "view_confirm": ut.GetMessage("view_confirm"), "view_report": ut.GetMessage("view_report"),51 "view_list": ut.GetMessage("view_list"), "view_report_key": ut.GetMessage("view_report_key"),52 "view_install": ut.GetMessage("view_install"), "view_installed": ut.GetMessage("view_installed"),53 "view_name": ut.GetMessage("view_name"), "view_description": ut.GetMessage("view_description"),54 "view_type": ut.GetMessage("view_type"), "view_filename": ut.GetMessage("view_filename"),55 "view_label": ut.GetMessage("view_label"), "view_delete": ut.GetMessage("view_delete"),56 "view_configuration": ut.GetMessage("view_configuration"), "env_result": []nt.SM{},57 "view_envkey": ut.GetMessage("view_envkey"), "view_envvalue": ut.GetMessage("view_envvalue"),58 }59}60func (adm *AdminService) Home(w http.ResponseWriter, r *http.Request) {61 data := adm.parseData(r)62 adm.render(w, "login", data)63}64func (adm *AdminService) Login(w http.ResponseWriter, r *http.Request) {65 data := adm.parseData(r)66 if data["database"] == "" {67 data["errors"].(nt.SM)["login"] = ut.GetMessage("missing_database")68 adm.render(w, "login", data)69 return70 }71 nstore := adm.GetNervaStore(data["database"].(string))72 token, _, err := (&nt.API{NStore: nstore}).UserLogin(data)73 if err != nil {74 data["errors"].(nt.SM)["login"] = err.Error()75 adm.render(w, "login", data)76 return77 }78 if nstore.User.Scope != "admin" {79 data["errors"].(nt.SM)["login"] = ut.GetMessage("admin_rights")80 adm.render(w, "login", data)81 return82 }83 data["token"] = token84 data["password"] = ""85 adm.render(w, "admin", data)86}87func (adm *AdminService) Menu(w http.ResponseWriter, r *http.Request) {88 data := adm.parseData(r)89 switch data["menu"] {90 case "database":91 adm.render(w, "database", data)92 case "theme":93 if data["theme"] == "" || data["theme"] == "light" {94 data["theme"] = "dark"95 } else {96 data["theme"] = "light"97 }98 adm.render(w, r.PostFormValue("pageID"), data)99 case "logout":100 data["token"] = ""101 adm.render(w, "login", data)102 default:103 adm.render(w, "login", data)104 }105}106func (adm *AdminService) Admin(w http.ResponseWriter, r *http.Request) {107 data := adm.parseData(r)108 unauthorized := func(errMsg string) {109 data["errors"].(nt.SM)["login"] = errMsg110 adm.render(w, "login", data)111 }112 nstore := adm.GetNervaStore(data["database"].(string))113 err := (&nt.API{NStore: nstore}).TokenLogin(nt.IM{"token": data["token"].(string), "keys": adm.GetTokenKeys()})114 if err != nil {115 unauthorized(err.Error())116 return117 }118 if nstore.User == nil || nstore.User.Scope != "admin" {119 unauthorized(ut.GetMessage("admin_rights"))120 return121 }122 switch r.PostFormValue("cmd") {123 case "refresh":124 data["token"], err = (&nt.API{NStore: nstore}).TokenRefresh()125 case "password":126 err = (&nt.API{NStore: nstore}).UserPassword(data)127 if err == nil {128 data["success"] = ut.GetMessage("password_change")129 data["password"] = ""130 data["confirm"] = ""131 }132 case "list":133 data["result"], err = (&nt.API{NStore: nstore}).ReportList(data)134 case "install":135 var id int64136 id, err = (&nt.API{NStore: nstore}).ReportInstall(nt.IM{"reportkey": ut.ToString(data["reportkey"], "")})137 if err == nil {138 data["success"] = fmt.Sprintf(ut.GetMessage("result_id"), id)139 data["reportkey"] = ""140 }141 case "delete":142 err = (&nt.API{NStore: nstore}).ReportDelete(nt.IM{"reportkey": ut.ToString(data["reportkey"], "")})143 if err == nil {144 data["success"] = ut.GetMessage("successful_delete")145 data["reportkey"] = ""146 }147 case "env_list":148 envResult := make([]nt.SM, 0)149 keys := make([]string, 0)150 configs := nt.IM{}151 for key, value := range adm.Config {152 keys = append(keys, key)153 configs[key] = value154 }155 for _, env := range os.Environ() {156 if strings.HasPrefix(env, "NT_ALIAS_") {157 configs[strings.Split(env, "=")[0]] = strings.Split(env, "=")[1]158 }159 }160 sort.Strings(keys)161 for _, key := range keys {162 envResult = append(envResult, nt.SM{"envkey": strings.ToUpper(key), "envvalue": ut.ToString(adm.Config[key], "")})163 }164 data["env_result"] = envResult165 }166 if err != nil {167 data["errors"].(nt.SM)["admin"] = err.Error()168 }169 adm.render(w, "admin", data)170}171func (adm *AdminService) Database(w http.ResponseWriter, r *http.Request) {172 data := adm.parseData(r)173 if adm.Config["NT_API_KEY"] != data["apikey"] {174 data["errors"].(nt.SM)["database"] = ut.GetMessage("invalid_api_key")175 adm.render(w, "database", data)176 return177 }178 data["result"], _ = (&nt.API{NStore: nt.New(&db.SQLDriver{Config: adm.Config}, adm.Config)}).DatabaseCreate(data)179 adm.render(w, "database", data)180}...
cli.go
Source:cli.go
1package app2import (3 "errors"4 "flag"5 "fmt"6 "strings"7 nt "github.com/nervatura/nervatura/service/pkg/nervatura"8 srv "github.com/nervatura/nervatura/service/pkg/service"9 ut "github.com/nervatura/nervatura/service/pkg/utils"10)11type cliServer struct {12 app *App13 service srv.CLIService14 args nt.SM15 result string16}17func init() {18 registerService("cli", &cliServer{})19}20// StartService - Start Nervatura CLI server21func (s *cliServer) StartService() error {22 s.service = srv.CLIService{23 Config: s.app.config,24 GetNervaStore: s.app.GetNervaStore,25 }26 s.args = s.app.args27 if s.app.args == nil {28 s.parseFlags()29 }30 if s.args["cmd"] == "server" {31 s.result = "server"32 return nil33 }34 err := s.checkRequired()35 if err != nil {36 if s.app.args == nil {37 flag.Usage()38 }39 return err40 }41 s.result, err = s.parseCommand()42 if err != nil {43 return err44 }45 if s.app.args == nil {46 fmt.Println(s.result)47 }48 return nil49}50func (s *cliServer) Results() string {51 return s.result52}53func (s *cliServer) ConnectApp(app interface{}) {54 s.app = app.(*App)55}56func (s *cliServer) StopService(interface{}) error {57 return nil58}59func (s *cliServer) parseFlags() {60 s.args = make(nt.SM)61 var cmds = []string{"server", "Delete", "Function", "Get", "Update", "View",62 "UserPassword", "TokenLogin", "TokenRefresh", "UserLogin", "DatabaseCreate",63 "Report", "ReportDelete", "ReportInstall", "ReportList", "TokenDecode"}64 var cmdsO = []string{"Delete", "Function", "Get", "Update", "UserPassword",65 "UserLogin", "DatabaseCreate", "Report", "ReportDelete", "ReportInstall", "ReportList"}66 var cmdsNT = []string{"Update"}67 var cmdsD = []string{"Update", "View"}68 var cmdsK = []string{"DatabaseCreate"}69 var help bool70 flag.BoolVar(&help, "help", false, ut.GetMessage("cli_usage"))71 var env string72 flag.StringVar(&env, "env", "", ut.GetMessage("cli_flag_env"))73 var cmd string74 flag.StringVar(&cmd, "c", "server", ut.GetMessage("cli_flag_c")+strings.Join(cmds[:10], ", ")+",\n"+strings.Join(cmds[10:], ", "))75 var token string76 flag.StringVar(&token, "t", "", ut.GetMessage("cli_flag_t"))77 var options string78 flag.StringVar(&options, "o", "", ut.GetMessage("cli_flag_o")+strings.Join(cmdsO[:8], ", ")+",\n"+strings.Join(cmdsO[8:], ", "))79 var ntype string80 flag.StringVar(&ntype, "nt", "", ut.GetMessage("cli_flag_nt")+strings.Join(cmdsNT, ", "))81 var data string82 flag.StringVar(&data, "d", "", ut.GetMessage("cli_flag_d")+strings.Join(cmdsD, ", "))83 var key string84 flag.StringVar(&key, "k", "", ut.GetMessage("cli_flag_k")+strings.Join(cmdsK, ", "))85 flag.Usage = func() {86 flag.PrintDefaults()87 }88 flag.Parse()89 s.args["cmd"] = cmd90 if help {91 s.args["cmd"] = "help"92 }93 if token != "" {94 s.args["token"] = token95 }96 if options != "" {97 s.args["options"] = options98 }99 if data != "" {100 s.args["data"] = data101 }102 if ntype != "" {103 s.args["nervatype"] = ntype104 }105 if key != "" {106 s.args["key"] = key107 }108}109func (s *cliServer) checkRequired() (err error) {110 if value, found := s.args["token"]; (!found || value == "") &&111 s.args["cmd"] != "UserLogin" && s.args["cmd"] != "DatabaseCreate" && s.args["cmd"] != "help" {112 return errors.New(ut.GetMessage("missing_parameter") + ": token(-t)")113 }114 switch s.args["cmd"] {115 case "Delete", "Function", "Get", "UserPassword",116 "UserLogin", "Report", "ReportDelete", "ReportInstall", "ReportList":117 if value, found := s.args["options"]; !found || value == "" {118 return errors.New(ut.GetMessage("missing_parameter") + ": options(-o)")119 }120 case "DatabaseCreate":121 if value, found := s.args["options"]; !found || value == "" {122 return errors.New(ut.GetMessage("missing_parameter") + ": options(-o)")123 }124 if value, found := s.args["key"]; !found || value == "" {125 return errors.New(ut.GetMessage("missing_parameter") + ": API key(-k)")126 }127 case "View":128 if value, found := s.args["data"]; !found || value == "" {129 return errors.New(ut.GetMessage("missing_parameter") + ": data(-d)")130 }131 case "Update":132 if value, found := s.args["nervatype"]; !found || value == "" {133 return errors.New(ut.GetMessage("missing_parameter") + ": nervatype(-nt)")134 }135 if value, found := s.args["data"]; !found || value == "" {136 return errors.New(ut.GetMessage("missing_parameter") + ": data(-d)")137 }138 }139 return nil140}141// parseCommand - Parse s.args from command line parameters142func (s *cliServer) parseCommand() (result string, err error) {143 if s.args["cmd"] == "help" {144 flag.Usage()145 return "", nil146 }147 var api *nt.API148 if _, found := s.args["token"]; found {149 if s.args["cmd"] == "TokenDecode" {150 return s.service.TokenDecode(s.args["token"]), nil151 }152 api, result = s.service.TokenLogin(s.args["token"], s.app.tokenKeys)153 if api == nil || s.args["cmd"] == "TokenLogin" {154 return result, nil155 }156 }157 var options nt.IM158 if _, found := s.args["options"]; found {159 if err = ut.ConvertFromByte([]byte(s.args["options"]), &options); err != nil {160 return "", errors.New(ut.GetMessage("invalid_json"))161 }162 }163 var data []nt.IM164 if _, found := s.args["data"]; found {165 if err = ut.ConvertFromByte([]byte(s.args["data"]), &data); err != nil {166 return "", errors.New(ut.GetMessage("invalid_json"))167 }168 }169 apiMap := map[string]func(api *nt.API) string{170 "UserLogin": func(api *nt.API) string {171 return s.service.UserLogin(options)172 },173 "UserPassword": func(api *nt.API) string {174 return s.service.UserPassword(api, options)175 },176 "TokenRefresh": func(api *nt.API) string {177 return s.service.TokenRefresh(api)178 },179 "Get": func(api *nt.API) string {180 return s.service.Get(api, options)181 },182 "View": func(api *nt.API) string {183 return s.service.View(api, data)184 },185 "Function": func(api *nt.API) string {186 return s.service.Function(api, options)187 },188 "Update": func(api *nt.API) string {189 return s.service.Update(api, s.args["nervatype"], data)190 },191 "Delete": func(api *nt.API) string {192 return s.service.Delete(api, options)193 },194 "DatabaseCreate": func(api *nt.API) string {195 return s.service.DatabaseCreate(s.args["key"], options)196 },197 "Report": func(api *nt.API) string {198 return s.service.Report(api, options)199 },200 "ReportList": func(api *nt.API) string {201 return s.service.ReportList(api, options)202 },203 "ReportInstall": func(api *nt.API) string {204 return s.service.ReportInstall(api, options)205 },206 "ReportDelete": func(api *nt.API) string {207 return s.service.ReportDelete(api, options)208 },209 }210 if _, found := apiMap[s.args["cmd"]]; !found {211 return "", errors.New(ut.GetMessage("invalid_command") + ": " + s.args["cmd"] + " (-c)")212 }213 return apiMap[s.args["cmd"]](api), nil214}...
install-packages.go
Source:install-packages.go
...45 return46}47func exeCmds(cmds []CommandType) (err error) {48 for _, cmd := range cmds {49 log.Info().Msg(getMessage(cmd, DOING_STATE))50 if e := cmd.Command.Run(); e != nil {51 if IGNORE_VERIFY {52 log.Warn().Msg(getMessage(cmd, FAILED_STATE))53 } else {54 log.Error().Msg(getMessage(cmd, FAILED_STATE))55 err = e56 return57 }58 } else {59 log.Info().Msg(getMessage(cmd, DONE_STATE))60 }61 }62 return63}...
getMessage
Using AI Code Generation
1install.getMessage()2install.getMessage()3install.getMessage()4install.getMessage()5install.getMessage()6install.getMessage()7install.getMessage()8install.getMessage()9install.getMessage()10install.getMessage()11install.getMessage()12install.getMessage()13install.getMessage()14install.getMessage()15install.getMessage()16install.getMessage()17install.getMessage()18install.getMessage()19install.getMessage()20install.getMessage()21install.getMessage()22install.getMessage()23install.getMessage()24install.getMessage()25install.getMessage()
getMessage
Using AI Code Generation
1import "fmt"2func main() {3 fmt.Println(install.getMessage())4}5import "fmt"6import "install"7func main() {8 fmt.Println(install.getMessage())9}10 /usr/local/go/src/pkg/install (from $GOROOT)11 /home/user/go/src/install (from $GOPATH)
getMessage
Using AI Code Generation
1import (2func main() {3 fmt.Println(install.GetMessage())4}5import (6func main() {7 fmt.Println(install.GetMessage())8}
getMessage
Using AI Code Generation
1import (2func main() {3 fmt.Println(install.GetMessage())4}5import (6func main() {7 fmt.Println(install.GetMessage())8}9import (10func main() {11 fmt.Println(install.GetMessage())12}13import (14func main() {15 fmt.Println(install.GetMessage())16}17import (18func main() {19 fmt.Println(install.GetMessage())20}21import (22func main() {23 fmt.Println(install.GetMessage())24}25import (26func main() {27 fmt.Println(install.GetMessage())28}29import (30func main() {31 fmt.Println(install.GetMessage())32}33import (34func main() {35 fmt.Println(install.GetMessage())36}37import (38func main() {39 fmt.Println(install.GetMessage())40}
getMessage
Using AI Code Generation
1import (2func main() {3 fmt.Println(install.getMessage())4}5The package name is used to import the package. For example, we have imported the package using the following statement:6import "install"
getMessage
Using AI Code Generation
1import (2func main() {3 fmt.Println(install.GetMessage())4}5Now you can import the package using the following command:6import "GoPackageExample/install"
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!