Posts

win - cmd- network

Image
 network

Go - local MS SQL

  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(){         rd := model.Punch{}         rows.Scan(&rd.Date, &rd.Name, &rd.Time)         d = append(d,rd)

Go - connect remote SQL server

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 = append(conf, "integrated security=SSPI" )     }     conf = append(conf, "Initial Catalog=" +m.database)     conf = append(conf, "user id=" +m.sa.user)     conf = ap

Go - mail

Image
  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

Image
 >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 , },

pfSense local DNS sever

Image
  http://192.1.2.101                                              add dhcp static map set up domain add DNS server IP