Golang学习

收录了 6 篇文章 · 2 人关注

  • golng 使用postgres数据库

    ```go package main import ( "fmt" "log" "time" "github.com/go-xorm/xorm" _ "github.com/lib/pq" ) var engine *xorm.Engine func main() { } func init() { psqlInfo := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s...

  • golang redis连接池的使用

    ````golang package main import ( "encoding/json" "errors" "fmt" "time" "github.com/garyburd/redigo/redis" ) const ( RedisURL = "redis://*****:6379" redisMaxIdle = 3 //最大空闲连接数 redisIdleTimeoutSec = 240 //最...

  • RSA生成密钥

    **RSA生成密钥** ````golang package crypto import ( "crypto/rand" "crypto/rsa" "crypto/x509" "encoding/pem" "os" ) func GenRsaKey(bits int) error { privateKey, err := rsa.GenerateKey(rand.Reader, bits) if err != nil { return er...

  • RSA加密与解密

    ### RSA加密与解密 ````golang package crypto import ( "crypto/rand" "crypto/rsa" "crypto/x509" "encoding/pem" "errors" "io/ioutil" ) func RsaEncrypt(origData []byte) ([]byte, error) { publicKey, err := ioutil.ReadFile("public.pem")...

  • 解决golang https请求提示x509: certificate signed by unknown authority

    Golang https请求发生错误 ` x509: certificate signed by unknown authority ` ### 重点: 引入"crypto/tls" ````golang import ( "crypto/tls" "log" "net/http" ) func get(url string, headers map[string]string) *http.Response { tr := &http.Transport{ ...

  • gin web框架解决跨域问题

    <pre><code> func Cors() gin.HandlerFunc { return func(c *gin.Context) { method := c.Request.Method if method == "OPTIONS" { c.JSON(http.StatusOK, "Options Request!") } origin := c.Request.Header.Get("Origin") var headerKeys []...