Posts

Showing posts from January, 2022

Go - "gopls requires a module at the root of your workspace."

Image
  https://github.com/golang/tools/blob/master/gopls/doc/settings.md Just add the following to your  settings.json : //golang "gopls" : { "experimentalWorkspaceModule" : true , },

Go with Heroku

Image
把套件下載下來, 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 origi

Mysql - CRUD

Login       $mysql -u root -p      >use database; Exit      control + D View mysql> show tables ; +----------------+ | Tables_in_todo | +----------------+ | TODO           | +----------------+ 1 row in set (0.00 sec) mysql> describe TODO ; +-------+---------------+------+-----+---------+-------+ | Field | Type          | Null | Key | Default | Extra | +-------+---------------+------+-----+---------+-------+ | name  | varchar(20)   | YES  |     | NULL    |       | | task  | varchar(1000) | YES  |     | NULL    |       | +-------+---------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> select * from TODO ; +------+---------------------+ | name | task                | +------+---------------------+ | eve  | being a golang dev. | | eve  | being a golang dev. | | eve  | being a golang dev. | | eve  | being a golang dev. | | eve  | being a golang dev. | +------+---------------------+ 5 rows in set (0.00 sec) C  - create database or table      CREATE DATAB

Go - Json Encoder

package main import ( "encoding/json" "fmt" "net/http" ) type Response struct { Code int `json:"Code"` Body interface {} `json:"Body"` //"interface{}" = anyType } func handler(w http.ResponseWriter, r *http.Request){ //documentwrite w.Write([]byte( "<h1>Hello server</h1>" )) //utf-8 fmt.Println(r.Method) //curl -X POST localhost:3000 if r.Method == http.MethodGet{ data := Response{ Code: http.StatusOK, Body: "hi" , } json.NewEncoder(w).Encode(data) } } func main(){ //Mux mux := http.NewServeMux() //request , callback mux.HandleFunc( "/" ,handler) //指定該路徑(router)"/", registers此路徑func //resume http.ListenAndServe( "localhost:3000" ,mux) }

Go - Server

  package main import ( "fmt" "net/http" ) func handler(w http.ResponseWriter, r *http.Request){ //documentwrite w.Write([]byte( "<h1>Hello server</h1>" )) //utf-8 fmt.Println(r.Method) //GET; POST: curl -X POST localhost:3000 } func main(){ //Mux mux := http.NewServeMux() //request , callback mux.HandleFunc( "/" ,handler) //指定該路徑(router)"/", registers此路徑func //resume http.ListenAndServe( "localhost:3000" ,mux) }

Go - GET vs POST

Image
 

Go - add package "go.mod "and "go.sum"

Image
add inside self-define packages by name your app: $go mod init  project-name add outside package $go get github.com/360EntSecGroup-Skylar/excelize

Mysql syntax — select Top3

$topThree = " SELECT score.groupID, SUM(cd + doc + tech + func) AS 總分  FROM score  GROUP BY score.groupID LIMIT 3 ; " ; $name = " SELECT score.groupID, IOS110.project_name FROM score INNER JOIN IOS110 ON score.groupID = IOS110.groupID; " ; $topThreeWithProjectNameSQL = " SELECT IOS110.project_name, score.groupID, SUM(score.cd + score.doc + score.tech + score.func) AS 總分  FROM score, IOS110  WHERE score.groupID = IOS110.groupID  GROUP BY score.groupID,IOS110.project_name LIMIT 3 ; " ;

Golang - get object type

package main import ( "fmt" "reflect" ) func main() { getObjType() } func getObjType(){ tst := "string" fmt.Println(reflect.TypeOf(tst)) }

Go install

Image
Download Go export PATH=”/usr/local/go/bin:/$PATH” add “Go” VScode extension

PHP Laravel - Composer install then Create a Laravel project

Image
 1. https://getcomposer.org/download/ 2. https://getcomposer.org/doc/00-intro.md 3. https://laravel.com/docs/8.x#installation-via-composer 4. 5.