关闭
当前搜索:

Go1.10在编译成dll小实例

package mainimport ( "net" ) //必须导入 import "C"//编译成动态库也是必须的 func main() {}//export Interfaces func Interfaces(list []string, retlen *int) string { interf, err := net.InterfaceAddrs() if err...
阅读(46) 评论(0)

Go1.9接入prometheus监控小实例

package mainimport ( "bytes" "fmt" "net/http" "strings" "sync/atomic" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/expfmt" )type statusColle...
阅读(31) 评论(0)

Go1.9安全的限制net.Listener接入连接数

package mainimport ( "fmt" "net" "sync" "sync/atomic" )func main() { lis, err := net.Listen("tcp", ":1789") if err != nil { return } lis = LimitListener(lis, 1) }...
阅读(46) 评论(0)

Go开发环境设置,包含第三方包下载使用技巧

一、安装Go环境:①下载地址: 官方下载 国内社区下载 ②下载好对应的版本后,解压放入自己需要的路径这里我放在根目录下. linux: 环境变量设置: 一般放入:(/etc/profile)中 export GOBIN=/go/bin 声明Go可执行文件路径 export GOROOT=/go 声明Go根目录路径 export GOP...
阅读(96) 评论(0)

Go1.9帮同事写个备份上传小程序,带推告警到open-falcon功能

package mainimport ( "archive/zip" "encoding/json" "flag" "io/ioutil" "log" "net/http" "os" "strings" "time" "github.com/jlaffaye/ftp" )type Config struct { E...
阅读(399) 评论(0)

Go1.9获取rsa证书的指纹码

package mainimport ( "crypto/sha1" "encoding/hex" "fmt" "github.com/czxichen/work-stacks/tools/encrypt" )const c = `-----BEGIN CERTIFICATE----- MIICeTCCAiOgAwIBAgIICqroUds7aqYwDQYJKoZIhv...
阅读(206) 评论(0)

Go1.9不使用http2提高http传输效率

内部应用对外提供httpAPI,QPS提不上去,于是对接口进行了改造,将短链接改成长连接,在长连接上做数据交互.QPS有了显著提高,代码片段.内部实现是自定义解析http的,类似于fasthttp的方法,需要时解析,这里是用标准库的方法做的小实例package mainimport ( "bufio" "io" "log" "net" "net/http"...
阅读(253) 评论(0)

Go1.9组播发送消息小实例

package mainimport ( "flag" "fmt" "net" "syscall" )var ( ttl int daemon bool port = 12389 multiaddr = [4]byte{224, 0, 1, 1} inaddr_any = [4]byte{0,...
阅读(305) 评论(0)

Go1.9基于http备份文件中心服务器

package mainimport ( "archive/zip" "crypto/md5" "encoding/hex" "encoding/json" "flag" "io" "io/ioutil" "log" "net" "net/http" "net/url" "os" "path/fi...
阅读(221) 评论(0)

Go1.9获取Windows进程专用内存工作集

package main/* #include #include void CountPrivate(PSAPI_WORKING_SET_INFORMATION* workSetInfo,int* count) { int workSetPrivate = 0; for (ULONG_PTR i = 0; i N...
阅读(399) 评论(0)

Go1.9windows创建服务小实例

package mainimport ( "context" "fmt" "log" "net" "net/http" "os" "github.com/kardianos/service" )type services struct { log service.Logger srv *http.Server cfg *s...
阅读(650) 评论(0)

Go1.9按行读取日志文件并处理

package mainimport ( "bufio" "bytes" "context" "log" "os" "sync" )const ( logname = "log" concurrent = 5 //并发处理数,可以根据物理内存调整 maxsize = 10 * 1024...
阅读(649) 评论(0)

Go1.9 tcpproxy代理小实现

package mainimport ( "io" "log" "net" "strings" "sync" "time" )func main() {}type remote struct { mu sync.Mutex addr string inactive bool }func (r *remote)...
阅读(332) 评论(0)

Golang1.8编译静态库给C使用

Go实例代码:package mainimport ( "fmt" )import "C"//export Printf func Printf(format, str string) { fmt.Printf(format, str) }func main(){} 编译命令: go build -ldflags “-s -w” -buildmode=c-archive -o pr...
阅读(1154) 评论(0)

Go1.8实现watchdog功能,实现依赖启动服务程序

package mainimport ( "flag" "fmt" "io" "os" "os/signal" "os/user" "path" "strconv" "strings" "sync" "syscall" "time" "github.com/czxichen/command/watc...
阅读(780) 评论(0)
165条 共11页1 2 3 4 5 ... 下一页 尾页
    个人资料
    • 访问:199789次
    • 积分:3649
    • 等级:
    • 排名:第9785名
    • 原创:163篇
    • 转载:2篇
    • 译文:0篇
    • 评论:33条
    文章分类
    最新评论