摘要:
代码示例 package main import ( "fmt" "time" ) //使用channel 实现互斥锁 type Mutex struct { ch chan struct{} } //初始化锁 func NewMutex() *Mutex { mu := &Mutex{make(c 阅读全文
posted @ 2021-01-22 12:47
pebblecome
阅读(591)
评论(0)
推荐(0)
摘要:
1,once 方式实现 package main import ( "sync" "sync/atomic" ) //单例模式 type Singleton struct {} var instance *Singleton var once sync.Once var mu sync.Mutex 阅读全文
posted @ 2021-01-22 12:45
pebblecome
阅读(263)
评论(0)
推荐(0)
摘要:
文件读实现示例 func ReadFileByRead(filename string){ file,err := os.Open(filename) if err !=nil{ fmt.Println("open file failed err :",err) return } defer fil 阅读全文
posted @ 2021-01-22 12:43
pebblecome
阅读(126)
评论(0)
推荐(0)
摘要:
安装 go get github.com/shirou/gopsutil 简单的代码示例 package main import ( "fmt" "github.com/shirou/gopsutil/cpu" "github.com/shirou/gopsutil/disk" host2 "git 阅读全文
posted @ 2021-01-22 12:40
pebblecome
阅读(714)
评论(0)
推荐(0)
摘要:
下载: go get -u github.com/jinzhu/gorm 简单代码: package main import ( "github.com/jinzhu/gorm" _ "github.com/jinzhu/gorm/dialects/mysql" "fmt" ) type Admin 阅读全文
posted @ 2021-01-22 12:37
pebblecome
阅读(84)
评论(0)
推荐(0)
摘要:
GET请求示例 import ( "encoding/json" "fmt" "io/ioutil" "net/http" "net/url" ) type Result struct { Args string `json:"args"` Headers map[string]string `js 阅读全文
posted @ 2021-01-22 12:35
pebblecome
阅读(2538)
评论(0)
推荐(0)
摘要:
代码示例 package main import ( "fmt" "os" "time" ) //time包练习 func main() { timeone := "" //当前时间 now := time.Now() time1 := now.Format("2006-01-02 15:04:05 阅读全文
posted @ 2021-01-22 12:33
pebblecome
阅读(49)
评论(0)
推荐(0)
摘要:
下载安装 go get -u golang.org/x/sync/semaphore 简单的代码实现 package main import ( "context" "fmt" "golang.org/x/sync/semaphore" "log" "runtime" "time" ) /* 我们创 阅读全文
posted @ 2021-01-22 12:32
pebblecome
阅读(90)
评论(0)
推荐(0)
摘要:
Kafka介绍 Kafka是Apache软件基金会开发的一个开源流处理平台,由Java和Scala编写;Kafka是一种高吞吐、分布式、基于订阅发布的消息系统。 Kafka名称解释 Producer:生产者 Consumer:消费者 Topic:消息主题,每一类的消息称之为一个主题 Broker:K 阅读全文
posted @ 2021-01-22 11:52
pebblecome
阅读(425)
评论(0)
推荐(0)
摘要:
直接上代码,看怎么使用吧 package main import ( "fmt" "github.com/sirupsen/logrus" "os" ) var log = logrus.New() func initLog() error { file,err := os.OpenFile("lo 阅读全文
posted @ 2021-01-22 11:49
pebblecome
阅读(275)
评论(0)
推荐(0)

浙公网安备 33010602011771号