golang 다운로드 URL 이동 https://golang.org/dl/ windows-amd64 선택
Next
이용 약관 같은 것임. 동의 체크 후 Next
설치 폴더 지정 Next
설치 준비 댔나? Install
인내의 시간... 시간이 좀 걸린다.
golang 설치 완료
명령어로 go 설치 확인
> go version
go version go1.17.3 windows/amd64
go.mod 라는 파일을 생성해 준다. 마치 package.json 같은 존재인 듯 하다.
go mod init ginTest
대충 이렇게 생김.
go get -u github.com/gin-gonic/gin@v1.7.2
go get -u github.com/gin-gonic/gin@v1.7.2
go get: added github.com/gin-contrib/sse v0.1.0
go get: added github.com/gin-gonic/gin v1.7.2
go get: added github.com/go-playground/locales v0.14.0
go get: added github.com/go-playground/universal-translator v0.18.0
go get: added github.com/go-playground/validator/v10 v10.9.0
go get: added github.com/golang/protobuf v1.5.2
go get: added github.com/json-iterator/go v1.1.12
go get: added github.com/leodido/go-urn v1.2.1
go get: added github.com/mattn/go-isatty v0.0.14
go get: added github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
go get: added github.com/modern-go/reflect2 v1.0.2
go get: added github.com/ugorji/go/codec v1.2.6
go get: added golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871
go get: added golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1
go get: added golang.org/x/text v0.3.7
go get: added google.golang.org/protobuf v1.27.1
go get: added gopkg.in/yaml.v2 v2.4.0
package main
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"aaa":"ssss",
})
})
r.Run()
}
확인
콘솔로그
go get -u github.com/go-sql-driver/mysql
package main
import (
"github.com/gin-gonic/gin"
"database/sql"
_"github.com/go-sql-driver/mysql"
)
func main() {
r := gin.Default()
r.GET("/selectSysTable", func(c *gin.Context) {
var variable string
var value string
var setTime string
db, err := sql.Open("mysql", "id:pass@tcp(ip:port)/dbName")
if err != nil {
panic(err)
}
defer db.Close()
err = db.QueryRow("SELECT variable, value, set_time FROM sys_config WHERE variable = 'statement_truncate_len'").Scan(&variable, &value, &setTime)
c.JSON(200, gin.H{
"variable":variable,
})
})
r.Run()
}