Go with Heroku

把套件下載下來, ex, import 裡的mysql
$go mod vendor


GitHub - Install 

$brew install git
$git version


Github -Set up


under the project folder
$git init
$git config user.name "eve"
$git config user.email "eve@gmail.com"
$git config --list

build & write .gitignore file 
$touch .gitignore
echo "
# 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" >> .gitignore

$git add .
$git commit -m "first commit"

//create branch "main"
$git branch -M main $git remote add origin https://github.com/eve/goAPI.git $git push -u origin main


Heroku -Install Heroku CLI


$brew install heroku/brew/heroku




To use the Heroku CLI's autocomplete --
  Via homebrew's shell completion:
    1) Follow homebrew's install instructions https://docs.brew.sh/Shell-Completion
        NOTE: For zsh, as the instructions mention, be sure compinit is autoloaded
              and called, either explicitly or via a framework like oh-my-zsh.
    2) Then run
      $ heroku autocomplete --refresh-cache
  OR
  Use our standalone setup:
    1) Run and follow the install steps:
      $ heroku autocomplete

Heroku - Set up

$heroku login 
$heroku create your-app-name
$git push heroku main:main //gitMain to herokuMain



Heroku - mysql









/*heroku
mysql://username:password@Hostname/database?reconnect=true
*/
func Connect() *sql.DB{
//sql.Open("mysql", "<username>:<pw>@tcp(<HOST>:<port>)/<dbname>")
// db, err := sql.Open("mysql","root:1234@tcp(localhost:3306)")
db, err := sql.Open("mysql","username:password@tcp(Hostname:3306)/database")
// db, err := sql.Open("mysql","root:1234@/TODO")//user:password@/dbname
if err != nil{
panic(err)
// log.Fatal(err)
}
fmt.Println("database connected")
con = db
return con
}







 

Comments

Popular posts from this blog

Go-VSCode -Autocomplete and Auto-import

Go - mail