From 30f403270f9d4e809c862a2ff7b845eba2ed4c50 Mon Sep 17 00:00:00 2001 From: Christos Ploutarchou Date: Wed, 1 Feb 2023 00:06:27 +0200 Subject: [PATCH 1/5] Modify install script add support for ARM64 cpu --- install.sh | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/install.sh b/install.sh index 9c41b95..c7b6c35 100755 --- a/install.sh +++ b/install.sh @@ -1,31 +1,28 @@ #!/bin/bash + userDir=$USER echo "Installing MicroGO binaries..." -curl -LJO https://github.com/cploutarchou/MicroGO/releases/download/v1.0.5/microGo -if [[ "$OSTYPE" == "linux-gnu"* ]]; then - if grep -q "alias microGo" ~/.zprofile; then - echo "Already exported" - sudo mv microGo /usr/local/bin/microGo - chmod +x /usr/local/bin/microGo + +if [[ "$OSTYPE" == "darwin"* ]]; then + if [[ $(uname -m) == "x86_64" ]]; then + curl -LJO https://github.com/cploutarchou/MicroGO/releases/download/v1.0.5/microGo + mv microGo /Users/"$userDir"/go/bin/microGo else - sudo mv microGo /usr/local/bin/microGo - chmod +x /usr/local/bin/microGo - echo "export PATH=$PATH:/usr/local/bin/microGo" >>/home/"$userDir"/.bashrc - echo "MicroGO binaries exported to PATH" - source /home/"$userDir"/.bashrc + curl -LJO https://github.com/cploutarchou/MicroGO/releases/download/v1.0.5/microGo-MacOS-ARM64 + mv microGo-MacOS-ARM64 /Users/"$userDir"/go/bin/microGo fi -elif [[ "$OSTYPE" == "darwin"* ]]; then - mv microGo /Users/"$userDir"/go/bin/microGo + echo "Enter your password to install MicroGO binaries using sudo" - chmod +x /Users/"$userDir"/go/bin/microGo # move to /usr/local/bin/microGo + chmod +x /Users/"$userDir"/go/bin/microGo echo "MicroGO binaries installed" echo "Export env" + if grep -q "alias microGo" ~/.zprofile; then echo "Already exported" else source ~/.zprofile comm="alias microGo=/Users/$userDir/go/bin/microGo" - echo $comm >>/Users/"$userDir"/.zprofile # add to .zprofile + echo $comm >>/Users/"$userDir"/.zprofile echo "MicroGO binaries exported to PATH" source ~/.zprofile fi From 50f4c398b94cd2e86d5fbe33c0ba0d00cde82f32 Mon Sep 17 00:00:00 2001 From: Christos Ploutarchou Date: Wed, 1 Feb 2023 22:28:36 +0200 Subject: [PATCH 2/5] update CHANGELOG --- CHANGELOG | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index b1d0395..1710c82 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,9 +1,19 @@ +### Version 1.0.6 +- Fix install script for MacOS and Linux for ARM architecture +- Fix bug for mailgun api +- Fix bug for sendgrid api +- Fix bug for sendinblue api +- Update README.md +- Update install script ### Version 1.0.5 - Create Request package - Fix import issues +- Fix bug in `get` method +- Fix bug in `post` method +- Fix bug in `put` method ### Version 1.0.4 - Create install script for MacOS - Fix import issues ### Version 1.0.3 ### Version 1.0.2 -### Version 1.0.1 \ No newline at end of file +### Version 1.0.1 From d1ed341ee28f3a4215e8d6b6bc6c186a1d74a5fb Mon Sep 17 00:00:00 2001 From: Christos Ploutarchou Date: Wed, 1 Feb 2023 22:30:31 +0200 Subject: [PATCH 3/5] apply some corrections --- cache/cache.go | 46 +++++++++++++++++++++++++++++--------------- mailer/mailer.go | 8 ++++---- microGo.go | 2 +- routes.go | 2 +- terminal/cli/main.go | 2 +- 5 files changed, 37 insertions(+), 23 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 5ee8ca0..3947232 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -23,11 +23,13 @@ type RedisCache struct { type Entry map[string]interface{} -//Exists : Check if the key exists +// Exists : Check if the key exists func (c *RedisCache) Exists(str string) (bool, error) { key := fmt.Sprintf("%s:%s", c.Prefix, str) conn := c.Connection.Get() - defer conn.Close() + defer func(conn redis.Conn) { + _ = conn.Close() + }(conn) ok, err := redis.Bool(conn.Do("EXISTS", key)) if err != nil { @@ -37,7 +39,7 @@ func (c *RedisCache) Exists(str string) (bool, error) { return ok, nil } -//encode : Encode a string/s of type entry +// encode : Encode a string/s of type entry func encode(item Entry) ([]byte, error) { b := bytes.Buffer{} e := gob.NewEncoder(&b) @@ -48,7 +50,7 @@ func encode(item Entry) ([]byte, error) { return b.Bytes(), nil } -//decode : Decode a string/s of type entry +// decode : Decode a string/s of type entry func decode(str string) (Entry, error) { item := Entry{} b := bytes.Buffer{} @@ -61,11 +63,13 @@ func decode(str string) (Entry, error) { return item, nil } -//Get : Return Key values from Redis if it exists. +// Get : Return Key values from Redis if it exists. func (c *RedisCache) Get(str string) (interface{}, error) { key := fmt.Sprintf("%s:%s", c.Prefix, str) conn := c.Connection.Get() - defer conn.Close() + defer func(conn redis.Conn) { + _ = conn.Close() + }(conn) cacheEntry, err := redis.Bytes(conn.Do("GET", key)) if err != nil { @@ -82,11 +86,13 @@ func (c *RedisCache) Get(str string) (interface{}, error) { return item, nil } -//Set : Set a key value in Redis +// Set : Set a key value in Redis func (c *RedisCache) Set(str string, value interface{}, expires ...int) error { key := fmt.Sprintf("%s:%s", c.Prefix, str) conn := c.Connection.Get() - defer conn.Close() + defer func(conn redis.Conn) { + _ = conn.Close() + }(conn) entry := Entry{} entry[key] = value @@ -110,11 +116,13 @@ func (c *RedisCache) Set(str string, value interface{}, expires ...int) error { return nil } -//Delete : Delete a key value in Redis. +// Delete : Delete a key value in Redis. func (c *RedisCache) Delete(str string) error { key := fmt.Sprintf("%s:%s", c.Prefix, str) conn := c.Connection.Get() - defer conn.Close() + defer func(conn redis.Conn) { + _ = conn.Close() + }(conn) _, err := conn.Do("DEL", key) if err != nil { @@ -124,11 +132,13 @@ func (c *RedisCache) Delete(str string) error { return nil } -//DeleteIfMatch : Delete a key values where match the with the key value +// DeleteIfMatch : Delete a key values where match the with the key value func (c *RedisCache) DeleteIfMatch(str string) error { key := fmt.Sprintf("%s:%s", c.Prefix, str) conn := c.Connection.Get() - defer conn.Close() + defer func(conn redis.Conn) { + _ = conn.Close() + }(conn) keys, err := c.getKeys(key) if err != nil { @@ -145,11 +155,13 @@ func (c *RedisCache) DeleteIfMatch(str string) error { return nil } -//Clean : Delete all entries from redis. +// Clean : Delete all entries from redis. func (c *RedisCache) Clean() error { key := fmt.Sprintf("%s:", c.Prefix) conn := c.Connection.Get() - defer conn.Close() + defer func(conn redis.Conn) { + _ = conn.Close() + }(conn) keys, err := c.getKeys(key) if err != nil { @@ -166,10 +178,12 @@ func (c *RedisCache) Clean() error { return nil } -//getKeys : Return all keys that match to the pattern. +// getKeys : Return all keys that match to the pattern. func (c *RedisCache) getKeys(pattern string) ([]string, error) { conn := c.Connection.Get() - defer conn.Close() + defer func(conn redis.Conn) { + _ = conn.Close() + }(conn) iter := 0 var keys []string diff --git a/mailer/mailer.go b/mailer/mailer.go index 8d4de6f..86d2b63 100644 --- a/mailer/mailer.go +++ b/mailer/mailer.go @@ -8,7 +8,7 @@ import ( "github.com/vanng822/go-premailer/premailer" defaultMail "github.com/xhit/go-simple-mail/v2" "html/template" - "io/ioutil" + "os" "path/filepath" "time" ) @@ -128,7 +128,7 @@ func (m *Mailer) SentSMTPMessage(msg Message) error { return nil } -//createHTMLMessage Build HTML Message using html template. +// createHTMLMessage Build HTML Message using html template. func (m *Mailer) createHTMLMessage(msg Message) (string, error) { renderTemplate := fmt.Sprintf("%s/%s.html.tmpl", m.Templates, msg.Template) t, err := template.New("email-html").ParseFiles(renderTemplate) @@ -144,7 +144,7 @@ func (m *Mailer) createHTMLMessage(msg Message) (string, error) { return fmtMSG, nil } -//createPlanMessage : Build HTML Message using plan template. +// createPlanMessage : Build HTML Message using plan template. func (m *Mailer) createPlanMessage(msg Message) (string, error) { renderTemplate := fmt.Sprintf("%s/%s.plain.tmpl", m.Templates, msg.Template) t, err := template.New("email-html").ParseFiles(renderTemplate) @@ -278,7 +278,7 @@ func (m *Mailer) addAPIAttachments(msg Message, tx *mail.Transmission) error { for _, x := range msg.Attachments { var attach mail.Attachment - content, err := ioutil.ReadFile(x) + content, err := os.ReadFile(x) if err != nil { return err } diff --git a/microGo.go b/microGo.go index 9276d76..e1696a9 100644 --- a/microGo.go +++ b/microGo.go @@ -25,7 +25,7 @@ import ( "github.com/robfig/cron/v3" ) -const version = "1.0.5" +const version = "1.0.6" var ( redisCache *cache.RedisCache diff --git a/routes.go b/routes.go index e2e8b84..9b31162 100644 --- a/routes.go +++ b/routes.go @@ -6,7 +6,7 @@ import ( "net/http" ) -//routes Return a Mux object that implements the Router interface. +// routes Return a Mux object that implements the Router interface. func (m *MicroGo) routes() http.Handler { mux := chi.NewRouter() mux.Use(middleware.RequestID) diff --git a/terminal/cli/main.go b/terminal/cli/main.go index ed14901..8e84e34 100644 --- a/terminal/cli/main.go +++ b/terminal/cli/main.go @@ -8,7 +8,7 @@ import ( "github.com/fatih/color" ) -const version = "1.0.5" +const version = "1.0.6" var micro microGo.MicroGo From 495fa714fb837dee6f96e78b1ef557009998c715 Mon Sep 17 00:00:00 2001 From: Christos Ploutarchou Date: Wed, 1 Feb 2023 22:30:57 +0200 Subject: [PATCH 4/5] update install.sh. Add support for ARM cpu's --- install.sh | 106 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 81 insertions(+), 25 deletions(-) diff --git a/install.sh b/install.sh index c7b6c35..7ec5d8e 100755 --- a/install.sh +++ b/install.sh @@ -1,31 +1,87 @@ #!/bin/bash - -userDir=$USER +echo "MicroGO Installation" +echo " ____ ____ _ ______ ___ " +echo "|_ \ / _| (_) .' ___ | .' \`. " +echo " | \/ | __ .---. _ .--. .--. / .' \_| / .-. \\ " +echo " | |\ /| | [ | / /'\`\\] [ \`/'\`\\ ] / .'\`\\ \ | | ____ | | | | " +echo " _| |_\/_| |_ | | | \\__. | | | \\__. | \\ \`\.___] | \\ \`-' / " +echo "|_____||_____| [___] '.___.' [___] '.__.' \`._____.' \`.___.' " +echo "" +echo "v1.0.6" +echo "Author: Christos Ploutarchou" echo "Installing MicroGO binaries..." +userDir=$USER + +spinner() { + local pid=$1 + local delay=0.75 + # shellcheck disable=SC1003 + local spinstr='|/-\' + # shellcheck disable=SC2143 + while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do + local temp=${spinstr#?} + printf " [%c] " "$spinstr" + local spinstr=$temp${spinstr%"$temp"} + sleep $delay + printf "\b\b\b\b\b\b" + done + printf " \b\b\b\b" +} if [[ "$OSTYPE" == "darwin"* ]]; then - if [[ $(uname -m) == "x86_64" ]]; then - curl -LJO https://github.com/cploutarchou/MicroGO/releases/download/v1.0.5/microGo - mv microGo /Users/"$userDir"/go/bin/microGo - else - curl -LJO https://github.com/cploutarchou/MicroGO/releases/download/v1.0.5/microGo-MacOS-ARM64 - mv microGo-MacOS-ARM64 /Users/"$userDir"/go/bin/microGo - fi - - echo "Enter your password to install MicroGO binaries using sudo" - chmod +x /Users/"$userDir"/go/bin/microGo - echo "MicroGO binaries installed" - echo "Export env" - - if grep -q "alias microGo" ~/.zprofile; then - echo "Already exported" - else - source ~/.zprofile - comm="alias microGo=/Users/$userDir/go/bin/microGo" - echo $comm >>/Users/"$userDir"/.zprofile - echo "MicroGO binaries exported to PATH" - source ~/.zprofile - fi + if [[ $(uname -m) == "x86_64" ]]; then + curl -LJO https://github.com/cploutarchou/MicroGO/releases/download/v1.0.6/microGo & + spinner $! + mv microGo /Users/"$userDir"/go/bin/microGo + else + curl -LJO https://github.com/cploutarchou/MicroGO/releases/download/v1.0.6/microGo-MacOS-ARM64 & + spinner $! + mv microGo-MacOS-ARM64 /Users/"$userDir"/go/bin/microGo + fi + + echo "Enter your password to install MicroGO binaries using sudo" + chmod +x /Users/"$userDir"/go/bin/microGo + echo "MicroGO binaries installed" + echo "Export env" + + if grep -q "alias microGo" ~/.zprofile; then + echo "Already exported" + else + # shellcheck disable=SC1090 + source ~/.zprofile + comm="alias microGo=/Users/$userDir/go/bin/microGo" + echo "$comm" >>/Users/"$userDir"/.zprofile + echo "MicroGO binaries exported to PATH" + # shellcheck disable=SC1090 + source ~/.zprofile + fi + +elif [[ "$OSTYPE" == "linux-gnu" ]]; then + if [[ $(uname -m) == "x86_64" ]]; then + curl -LJO https://github.com/cploutarchou/MicroGO/releases/download/v1.0.6/microGo-Linux-x86_64 & + spinner $! + mv microGo-Linux-x86_64 ~/go/bin/microGo + else + curl -LJO https://github.com/cploutarchou/MicroGO/releases/download/v1.0.6/microGo-Linux-ARM64 & + spinner $! + mv microGo-Linux-ARM64 ~/go/bin/microGo + fi + + chmod +x ~/go/bin/microGo + echo "MicroGO binaries installed" + echo "Export env" + + if grep -q "alias microGo" ~/.bashrc; then + echo "Already exported" + else + # shellcheck disable=SC1090 + source ~/.bashrc + comm="alias microGo=~/go/bin/microGo" + echo "$comm" >>~/.bashrc + echo "MicroGO binaries exported to PATH" + # shellcheck disable=SC1090 + source ~/.bashrc + fi else - echo "Unsupported OS" + echo "Unsupported OS" fi From c209face8c2b01675a1b8235cb30f4c39367082d Mon Sep 17 00:00:00 2001 From: Christos Ploutarchou Date: Wed, 1 Feb 2023 22:31:53 +0200 Subject: [PATCH 5/5] update install.sh. Add support for ARM cpu's --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 7ec5d8e..fc53c9b 100755 --- a/install.sh +++ b/install.sh @@ -30,7 +30,7 @@ spinner() { if [[ "$OSTYPE" == "darwin"* ]]; then if [[ $(uname -m) == "x86_64" ]]; then - curl -LJO https://github.com/cploutarchou/MicroGO/releases/download/v1.0.6/microGo & + curl -LJO https://github.com/cploutarchou/MicroGO/releases/download/v1.0.6/microGo-MacOS-x86_64 & spinner $! mv microGo /Users/"$userDir"/go/bin/microGo else