Skip to content

Commit

Permalink
Merge pull request #157 from cploutarchou/156-update-the-install-script
Browse files Browse the repository at this point in the history
Modify install script add support for ARM64 cpu
  • Loading branch information
cploutarchou authored Feb 1, 2023
2 parents 97a8820 + c209fac commit 0cd7445
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 53 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
### Version 1.0.1
46 changes: 30 additions & 16 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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{}
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
Expand Down
111 changes: 82 additions & 29 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,34 +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..."
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
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
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
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.6/microGo-MacOS-x86_64 &
spinner $!
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
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 "MicroGO binaries exported to PATH"
source ~/.zprofile
fi
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
8 changes: 4 additions & 4 deletions mailer/mailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion microGo.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/robfig/cron/v3"
)

const version = "1.0.5"
const version = "1.0.6"

var (
redisCache *cache.RedisCache
Expand Down
2 changes: 1 addition & 1 deletion routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion terminal/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/fatih/color"
)

const version = "1.0.5"
const version = "1.0.6"

var micro microGo.MicroGo

Expand Down

0 comments on commit 0cd7445

Please sign in to comment.