Posts
Showing posts from 2022
Go - local MS SQL
- Get link
- X
- Other Apps
package sqlsvr import ( "wms.api/model" "fmt" "database/sql" _ "github.com/denisenkom/go-mssqldb" ) //connect func ConnectDB() *sql.DB{ //connect // connStr := fmt.Sprintf("server=%s;usr id=%s;password=%s;port=%s;database=%s;", connStr := fmt.Sprintf( "server=%s;integrated security=SSPI;port=%s;usr id=%s;password=%s;database=%s;encrypt=disable;" , host,port,usr, pwd, dbName) fmt.Println(connStr) db, err := sql.Open( "mssql" ,connStr) model.IfErr(err, "connection:" ) // defer connDB.Close() return db } var db = sqlsvr.ConnectDB() tsql := "SELECT date,name,time FROM dbo.WORK;" rows, err := db.Query(tsql) model.IfErr(err, "error read Query:" ) defer rows.Close() var d []model.Punch for rows.Next(){ r...
Go - connect remote SQL server
- Get link
- X
- Other Apps
refer from: https://studygolang.com/articles/19117 package sqlsvr import ( "fmt" "database/sql" "strings" "wms.api/model" _ "github.com/denisenkom/go-mssqldb" _ "github.com/mattn/go-adodb" ) type Mssql struct { *sql.DB dataSource string database string windows bool sa SA } type SA struct { user string passwd string } func (m *Mssql) Open() (err error ) { var conf [] string conf = append(conf, "Provider=SQLOLEDB" ) conf = append(conf, "Data Source=" +m.dataSource) if m.windows { // Integrated Security=SSPI :以当前WINDOWS系统用户身去登录SQL SERVER服务器(需要在安装sqlserver时候设置), // 如果SQL SERVER服务器不支持这种方式登录时,就会出错。 conf = ...
Go - mail
- Get link
- X
- Other Apps
package main import ( "crypto/tls" "fmt" gomail "gopkg.in/gomail.v2" ) func main() { from := "eve@hello.com.tw" to := "eve@gmail.com" user := "eve" pwd := "pwd" host := `smtp.hello.com.tw` port := 25 m := gomail.NewMessage() m.SetHeader( "From" , from) m.SetHeader( "To" ,to) m.SetHeader( "Subject" , "Hello!" ) m.SetBody( "text/html" , "Hello <b>Eve</b>!" ) d := gomail.NewDialer(host, port, user, pwd) // x509: certificate signed by unknown authority的解决方法 d.TLSConfig = &tls.Config{InsecureSkipVerify: true } if err := d.DialAndSend(m); err != nil { panic(err) } fmt.Println( "mail send successfully!" ) } gmail need to enable POP IMAP less secure apps need to enable "less secure apps" on your Google Account var ( from = "coco@gmail.com" to = from user = ...
Go-VSCode -Autocomplete and Auto-import
- Get link
- X
- Other Apps
>goinstall //golang "[go]" :{ "editor.formatOnSave" : true , "editor.codeActionsOnSave" : { "source.organizeImports" : true }, }, "go.testOnSave" : true , "go.lintOnSave" : "package" , "go.formatTool" : "goimports" , "go.testFlags" : [ "-v" ], "go.autocompleteUnimportedPackages" : true , "gopls" : { "experimentalWorkspaceModule" : true , },
use Git Bash on Windows from the VS Code terminal
- Get link
- X
- Other Apps
setting.json "terminal.integrated.profiles.windows" : { "PowerShell" : { "source" : "PowerShell" , "icon" : "terminal-powershell" }, "Command Prompt" : { "path" : [ "${env:windir}\\Sysnative\\cmd.exe" , "${env:windir}\\System32\\cmd.exe" ], "icon" : "terminal-cmd" }, "GitBash" : { "path" : [ "C:\\Git\\bin\\bash.exe" ], "icon" : "terminal-bash" }, }, use "code" launch VScode $alias code=/c/Users/username/vscode/bin/code $ PATH=$PATH:code
Go - string format
- Get link
- X
- Other Apps
d - decimal integer o - octal integer O - octal integer with 0o prefix b - binary integer x - hexadecimal integer lowercase X - hexadecimal integer uppercase f - decimal floating point, lowercase F - decimal floating point, uppercase e - scientific notation (mantissa/exponent), lowercase E - scientific notation (mantissa/exponent), uppercase g - the shortest representation of %e or %f G - the shortest representation of %E or %F c - a character represented by the corresponding Unicode code point q - a quoted character U - Unicode escape sequence t - the word true or false s - a string v - default format #v - Go-syntax representation of the value T - a Go-syntax representation of the type of the value p - pointer address % - a double %% prints a single % res := fmt.Sprintf("%s is %d years old", name, age) https://zetcode.com/golang/string-format/
MS SQL - install MSSQL on Mac
- Get link
- X
- Other Apps
https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-docker-container-deployment?view=sql-server-ver15&pivots=cs1-bash $sudo docker pull mcr.microsoft.com/mssql/server:2019-latest $docker run --name sql_server -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=strong@pwd' -p 1401:1433 -d mcr.microsoft.com/mssql/server:2019-latest $docker ps $ npm install -g sql-cli docker ps $mssql -u sa -p <password> >>select @@version download AZURE connect MS SQL Server