Skip to content

Instantly share code, notes, and snippets.

View xigang's full-sized avatar
🎾
/*happy coding*/

Xigang Wang xigang

🎾
/*happy coding*/
View GitHub Profile
@xigang
xigang / database.go
Last active March 30, 2016 09:04
操作MySQL数据库
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
//"time"
)
/*
@xigang
xigang / verify.go
Created April 1, 2016 06:57
use publib key to verify in golang
package main
import (
"crypto"
"crypto/rsa"
"crypto/sha1"
"crypto/x509"
"encoding/base64"
"fmt"
)
@xigang
xigang / golog.go
Created April 5, 2016 07:07
golang log的简单操作
package main
import (
"flag"
"fmt"
"log"
"os"
)
var fpath *string = flag.String("d", "Null", "please input a file path.")
@xigang
xigang / isDirOrFile.go
Created April 7, 2016 02:23
判断路径及文件是否存在
// internal utility methods
func webTime(t time.Time) string {
ftime := t.Format(time.RFC1123)
if strings.HasSuffix(ftime, "UTC") {
ftime = ftime[0:len(ftime)-3] + "GMT"
}
return ftime
}
func dirExists(dir string) bool {
@xigang
xigang / initDatabase.go
Last active April 14, 2016 02:12
初始化数据库
const (
DBName = "rijin"
Host = "localhost"
User = "root"
Port = 3306
Password = "wangxigang"
Charset = "utf8"
)
func initDatabase() (err error) {
@xigang
xigang / toFixed.go
Created April 18, 2016 07:29
golang 精度问题.
func round(num float64) int {
return int(num + math.Copysign(0.5, num))
}
func toFixed(num float64, precision int) float64 {
output := math.Pow(10, float64(precision))
return float64(round(num * output)) / output
}
@xigang
xigang / read_line_from_file.go
Created May 3, 2016 14:48
从文件中一样一行的读取文件
package main
import (
"bufio"
"fmt"
"log"
"os"
)
func main() {
@xigang
xigang / read_line_from_file.go
Last active May 4, 2016 01:35
从文件中一样一行的读取文件
package main
import (
"bufio"
"fmt"
"log"
"os"
)
func main() {
package main
import "os/exec"
func main() {
app := "echo"
//app := "buah"
arg0 := "-e"
arg1 := "Hello world"
@xigang
xigang / options.go
Last active November 17, 2020 07:00
Functional options for friendly APIs
//http://lubia.cn/2016/05/22/functional-options-for-friendly-apis/
//http://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
package main
import (
"fmt"
)
type Options struct {
Name string