Posts

Showing posts from 2022

win_cmd_disk

Image
 

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

mysql syntax

rename table      alter table equip.history rename to report;

use Git Bash on Windows from the VS Code terminal

Image
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

install MySQL server and Workbrench in Win10

Image
 https://dev.mysql.com/downloads/file/?id=510038 Next > Execute next > next default setting Next > Next window + R > cmd $cd C:\Program Files\MySQL\MySQL Server 8.0\bin $mysql server -u root -p >show databases; >use mysql; >show tables; >select * from component; >create table  check path:  

Git install in window

Image
  then all "Next>" Done!

Go - string format

  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

Image
  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