Go语言中文网 为您找到相关结果 47

Golang操作excel文件

文件 处理前.png 处理后文件 处理后.png 1、将三个标签页放到一个标签页中; 2、在第二个文件中新加一列时间,内容为第一个文件的标签页名; 3、将值大于7200的内容标红颜色。 package main import ( "github.com/tealeg/xlsx" "fmt" "strconv" ) type ora struct { corp string //单位 name string //业务系统 name2 string //进程名 v1000 string //10点值 v2000 string //20点值 H string // 最大值 L string // 最小值 A string // 平均值 TIME string // 时间 } func readXl...阅读全文

博文 2019-05-10 19:35:10 发条家的橙子

go语言:log4go

go语言中日志框架log4go用法 [plain] view plaincopyprint? package main import ( l4g "github.com/alecthomas/log4go" ) func main() { l4g.AddFilter("stdout", l4g.DEBUG, l4g.NewConsoleLogWriter()) //输出到控制台,级别为DEBUG l4g.AddFilter("file", l4g.DEBUG, l4g.NewFileLogWriter("test.log", false)) //输出到文件,级别为DEBUG,文件名为test.log,每次追加该原文件 //l4g.LoadConfiguration("log.xml")//使...阅读全文

博文 2015-06-17 23:01:52 LvanNeo

关于golang中map的key的类型

golang中的map,的 key 可以是很多种类型,比如 bool, 数字,string, 指针, channel , 还有 只包含前面几个类型的 interface types, structs, arrays 显然,slice, map 还有 function 是不可以了,因为这几个没法用 == 来判断 原文如下: As mentioned earlier, map keys may be of any type that is comparable. The language spec defines this precisely, but in short, comparable types are boolean, numeric, string, pointer, channe...阅读全文

博文 2016-09-03 14:00:07 hificamera

Ubuntu上通过apt安装golang

Ubuntu · golang/go Wiki The Go project's official download page is at https://golang.org/dl/. If you're using Ubuntu 16.04 LTS, 18.04 LTS or 19.04 on amd64, arm64, armhf or i386, then you can use the longsleep/golang-backports PPA and install Go 1.13. sudo add-apt-repository ppa:longsleep/golang-backports sudo apt-get update sudo apt-get install go...阅读全文

博文 2019-10-21 18:32:47 aside section._1OhGeD

golang实现wav文件转换为mp3文件

本文并非golang内置的库进行wav转mp3,而是通过golang调用Linux的lame命令进行转换。 在Linux环境下,默认情况是没有安装lame,所以首先需要安装lame(个人保存下载文件:http://pan.baidu.com/s/1qWp71G4#path=%252Fsharesoft%252Flinux%252Flame)。 Linux lame 安装及使用: 1. 解压lame压缩文件:tar -vzxf lame-3.98.4.tar.gz 2. 转到解压后的文件目录,依次执行:“./configure --enable-shared”,“make”,“make install” 3. lame使用方法:lame xxx.wav xxx.mp3 (这样就能把xxx.wa...阅读全文

博文 2015-07-11 03:00:02 hezhixiong

golang time.Duration()的问题解疑

文: How to multiply duration by integer? 看到golang项目中的一段代码, -------------------------------------------------------------------------------------------------- You have to cast it to a correct format Playground. yourTime := rand.Int31n(1000) time.Sleep(time.Duration(yourTime) * time.Millisecond) If you will check documentation for sleep, you see that ...阅读全文

博文 2017-07-01 10:00:09 oxspirt

Google IP 最新地址

文地址:https://ideas.spkcn.com/technology/250.html 2015年 目前最新可以直接访问google的IP91.213.30.152173.194.77.142173.194.77.143173.194.77.152173.194.77.154173.194.77.163 查询google ip 地址范围nslookup -q=TXT _netblocks.google.com 114.114.114.114nslookup -q=TXT _netblocks2.google.com 114.114.114.114nslookup -q=TXT _netblocks3.google.com 114.114.114.114 IPV4:216.239.32...阅读全文

博文 2015-01-22 13:00:02 apexchu

golang – fmt 格式化参数

文 基本 %v the value in a default format when printing structs, the plus flag (%+v) adds field names %#v a Go-syntax representation of the value %T a Go-syntax representation of the type of the value %% a literal percent sign; consumes no value The default format for %v is: bool: %t int, int8 etc.: %d uint, uint8 etc.: %d, %#x if printed with %#v floa...阅读全文

博文 2017-04-30 12:00:24 中柠檬

关于golang中map的key的类型

golang中的map,的 key 可以是很多种类型,比如 bool, 数字,string, 指针, channel , 还有 只包含前面几个类型的 interface types, structs, arrays 显然,slice, map 还有 function 是不可以了,因为这几个没法用 == 来判断 原文如下: As mentioned earlier, map keys may be of any type that is comparable. The language spec defines this precisely, but in short, comparable types are boolean, numeric, string, pointer, channe...阅读全文

博文 2016-09-06 21:00:01 hificamera

【译】Golang中使用『弃用(Deprecate)』

Go语言很长时间都没有一套标记弃用API的定义规范。这几年,出现了个规范可以在文档当中添加弃用注释。 现在,标准库开始使用这个格式了。 举个例子,Go 1.8的包中sql/driver.Execer被弃用,这里增加了一套注释,它可以被godoc识别。 // Execer is an optional interface that may be implemented by a Conn. // // If a Conn does not implement Execer, the sql package's DB.Exec will // first prepare a query, execute the statement, and then close the // statement...阅读全文

博文 2017-02-10 15:55:43 Bryce

使用golang切割nginx日志

简单学习了golang/go语言的基础语法,做个定时切割nginx日志的小脚本练习下,感觉挺好使的~ 脚本代码如下,install后将脚本加入到crontab定时运行,当然golang也可以自己定时执行,这里加入到crontab运行,是因为golang进程有可能会被kill掉.... package main import ( "fmt" "os" "path/filepath" "syscall" "time" "strings" "os/exec" "io/ioutil" ) func main(){ //日志目录 srcDirPath := "/usr/local/nginx/logs" //存放切割日志目录 targetDirPath := "/usr/local/nginx/log...阅读全文

博文 2015-06-17 20:02:18 phpwww

goagent配置

1、根据网上文档,创建账户。 2、server:管理员身份运行!uploader.bat -> appid: xzzl -> email: xxx@gmail.com -> password -> 失败则多试几遍。3、local:proxy.ini -> appid: xzzl (一定别写错。。) 4、hosts配置(c:\windows\system32\driver\etc)(百度获取最新,无法保存编辑则修改再覆盖原文件),免得平时无法搜索。附1. 5、管理员身份!运行goagent.exe 6、据说可以加快chrome搜索: 输入chrome://flags/找到QUIC,启用SPDY/4 附1: #google-hosts-2015#base services216.58.209.1...阅读全文

博文 2015-02-06 03:00:01 comeonleo

Golang多线程文件传输

Golang多线程文件传输 ------------------------------ 前段时间抽空用Golang简单实现了一下多线程文件传输。 采用的方式为将待传输的文件拆分成多部分由多个协程同时传输。服务端在全部数据接收完成后将文件拼接还原为原文件。 服务端编译后直接执行,客户端至少需要带一个参数:待发送文件名 。另外更多参数中,第二参数为指定服务端最终生成的文件名。第三个参数为单次发送数据包的大小(单位:Byte),最大不超过18K。第四个参数为待发送文件拆分的个数,其对应发送的协程数量。 好了,下面是全部代...阅读全文

博文 2015-06-17 20:02:30 LvanNeo

Golang 实现 批量 jpg png 格式图片转webp

随着需求的增加,App 体积逐渐增大,精简App的最简单便捷的办法就是从资源文件(icon)入手. 谷歌推出的WEBP是个很好的选择,所以,我们需要把项目中用到的资源文件(icon)转换成webp格式 WebP是一种现代图像格式,可为Web上的图像提供出色的无损和有损压缩。使用WebP,网站管理员和Web开发人员可以创建更小,更丰富的图像,从而使Web更快。 与PNG相比,WebP无损图像的尺寸要小26%。在同等的SSIM质量指标下,WebP有损图像比同类JPEG图像 小25-34%。 无损WebP 支持透明性(也称为Alpha通道),而其额外字节仅为22%。对于可接受的有损RGB压缩,有损WebP还支持透明性,与PNG相比,文件大小通常小3倍。 批量转换图片为webp格式流程: 下载web...阅读全文

博文 2019-10-15 00:32:49 aside section ._1OhGeD

Go 复制文件

/** * Created with IntelliJ IDEA. * User: luosangnanka * Date: 13-7-16 * Time: 下午3:25 * To change this template use File | Settings | File Templates. */ package main import ( f "fmt" "io" "os" ) func main() { w, err := CopyFile("sb.log", "hellosb.log") if err != nil { f.Println(err.Error()) } f.Println(w) } func CopyFile(src, des string) (w int64, ...阅读全文

博文 2015-11-05 17:00:07 wh_luosangnanka5

golang aes ecb 加密

代码地址:https://github.com/FakerGit/go-tools 加密模式 AES ECB模式 PKCS7Padding填充 原理 整个明文分成若干段相同的小段,然后对每一小段进行加密。这个是不安全的,重复的原文块加密后会是重复的结果,很明显暴露明文的模式。 代码 func PKCS7Padding(ciphertext []byte, blockSize int) []byte { padding := blockSize - len(ciphertext)%blockSize padtext := bytes.Repeat([]byte{byte(padding)}, padding) return append(ciphertext, padtext...) } fu...阅读全文

博文 2019-07-27 14:32:38 HollowKnight

Google自己使用Go语言吗(From Go FAQ)

很多人比较关注Google自己怎么使用Go语言. 最近官方GoFAQ专门针对这个问题给出了答案. 公开的项目主要有以下几个地方: http://golang.org Google App Engine http://dl.google.com - Google下载服务(包括Chrome/Earth/apt-get等下载/更新) Vitess - Scaling MySQL databases for the web (YouTube在使用) 原文请参考: Is Google using Go internally...阅读全文

博文 2015-05-03 22:19:06 chai2010

go语言:log4go

go语言中日志框架log4go用法package main import ( l4g "github.com/alecthomas/log4go" ) func main() { l4g.AddFilter("stdout", l4g.DEBUG, l4g.NewConsoleLogWriter()) //输出到控制台,级别为DEBUG l4g.AddFilter("file", l4g.DEBUG, l4g.NewFileLogWriter("test.log", false)) //输出到文件,级别为DEBUG,文件名为test.log,每次追加该原文件 //l4g.LoadConfiguration("log.xml")//使用加载配置文件,类似与java的log4j.properti...阅读全文

博文 2015-06-17 23:01:50 x369201170

Is Go An Object Oriented Language?

To truly understand what it means to be ‘object-oriented’ you need to look back at the origination of the concept. The first object oriented language, simula, emerged in the 1960s. It introduced objects, classes, inheritance and subclasses, virtual methods, coroutines, and a lot more. Perhaps most importantly, it introduced a paradigm shift of thin...阅读全文

博文 2014-10-13 01:00:00 cszhouwei

Golang 取文本(字符串)中间

文:https://studygolang.com/articles/780 func GetBetweenStr(str, start, end string) string { n := strings.Index(str, start) if n == -1 { n = 0 } else { n = n + len(start) // 增加了else,不加的会把start带上 } str = string([]byte(str)[n:]) m := strings.Index(str, end) if m == -1 { m = len(str) } str = string([]byte(str)[:m]) return str ...阅读全文

博文 2018-12-06 12:34:43 大华日记

golang访问tar文件

golang访问tar文件 下面例子提取一个tar文件的内容: package main import ( "io" "os" "fmt" "path" "encoding/json" "archive/tar" ) func extract(tarfile string) { reader, err := os.Open(tarfile) if err != nil { fmt.Printf("ERROR: cannot read tar file, error=[%v]\n", err) return } defer reader.Close() tarReader := tar.NewReader(reader) for { header, err := tarReader.Next(...阅读全文

博文 2018-08-30 14:35:11 CodingCode

App测试-测试环境

在当下app横行的时代,APP测试是一件很重要的事情,那么重中之重则是测试环境了,我们如何将小小的苹果手机和安卓手机实现在内网环境(测试环境)呢? 首先一点毫无疑问,pc机(含mac机)可以任意游走网络环境,因为你可以编辑系统级别的hosts文件,那么对于一项封闭式的苹果手机呢?对于开源的乱七八糟的安卓手机呢? 如何线上线下? 如果线上线下使用的是两套域名系统,且线下的域名在线上能够解析到内网,那就不用操作任何东西了,那么程序猿就要幸苦的改代码,且小测试们也要测两边不同域名了~~呵呵哒! 实现方法借助工具:极路由~~~(非广告狗) 模拟器有模拟器的环境,下面会介绍,那么要是真机(手机线下调试)呢? 极路由中有一个功能插件,可以在路由器中定义hosts指向(如何玩极路由...阅读全文

终于看到golang的深入解读了

golang出来这么多年了,深入讲解的还是第一次看到 http://blog.jobbole.com/90574/ 这个是翻译的,原文: http://blog.altoros.com/golang-part-4-object-files-and-function-metadata.html $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split('\n').length; var $numbering = $('

    ').addClass('pre-numbering').hide(); $(this).addClass('has-numbering')...阅读全文

博文 2015-12-22 04:00:01 varding

Protobuf-3.6.1 安装

简介 protobuf是Google开发的一种数据描述语言,能够将结构化的数据序列化,可用于数据存储,通信协议等方面,官方版本支持Go, C++, Java, Python,社区版本支持更多语言。相对于JSON和XML具有以下优点:体积小: 消息大小只需要XML的1/10 ~ 1⁄3速度快: 解析速度比XML快20 ~ 100倍集成度高: 使用Protobuf的编译器,可以生成更容易在编程中使用的数据访问代码更好的兼容性: Protobuf设计的一个原则就是要能够很好地向下或向上兼容 安装 1、从https://github.com/protocolbuffers/protobuf/releases获取Protobuf编译器protocwget https://github.com/prot...阅读全文

博文 2018-09-12 12:34:41 㗊??㵘燚㙓㗊

Go 中的正则表达式

文 kinds of single-character expressions examples any character, possibly including newline (s=true) . character class [xyz] negated character class [^xyz] Perl character class (link) \d negated Perl character class \D ASCII character class (link) [[:alpha:]] negated ASCII character class [[:^alpha:]] Unicode character class (one-letter name) \pN Un...阅读全文

博文 2017-04-30 09:00:26 中柠檬

2.Go by Example: Values

Go has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples. Strings, which can be added together with + Integers and floats. Booleans, with boolean operators as you’d expect. package main import "fmt" func main() { fmt.Println("go" + "lang") fmt.Println("1+1 =", 1+1) fmt.Println("7.0/3.0 =", 7.0/3.0...阅读全文

博文 2015-06-17 20:15:57 u013487968

Go by Example: Recursion

Go语言支持递归函数。这里是一个经典例子:factorial 数列。 package main import "fmt" // fact函数不断地调用自身,直到达到基本状态fact(0) func fact(n int) int { if n == 0 { return 1 } return n * fact(n-1) } func main() { fmt.Println(fact(7)) }输出 $ go run recursion.go 5040 下一个例子: Go by Example:Pointer 英文原...阅读全文

博文 2015-06-17 23:08:15 codemanship

Golang语言--select

Golang语言--selectgolang的select与channel配合使用。它用于等待一个或者多个channel的输出。应用场景:主goroutine等待子goroutine完成,但是子goroutine无限运行,导致主goroutine会一直等待下去。而主线程想假如超过了一定的时没有返回的话,进行超时判断然后继续运行下去。 查看原文:http://www.zoues.com/2016/10/20/golang%e8%af%ad%e8%a8%80-select...阅读全文

博文 2016-10-20 08:00:07 u012798391

Golang分页

//分页方法,根据传递过来的页数,每页数,总数,返回分页的内容 7个页数 前 1,2,3,4,5 后 的格式返回,小于5页返回具体页数func Paginator(page, prepage int, nums int64) map[string]interface{} { var firstpage int //前一页地址 var lastpage int //后一页地址 //根据nums总数,和prepage每页数量 生成分页总数 totalpages := int(math.Ceil(float64(nums) / float64(prepage))) //page总数 if page > totalpages { page = totalpages } if page <= 0 { ...阅读全文

博文 2019-05-22 01:34:42 永远de明天

Creating A Simple Web Server With Golang

文: https://tutorialedge.net/post/golang/creating-simple-web-server-with-golang/ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- In this tutorial we’ll be focusing on creating a very simple web server using the net/http package. If ...阅读全文

博文 2017-07-01 10:00:17 oxspirt

golang defer

The arguments to the deferred function (which include the receiver if the function is a method) are evaluated when the defer executes, not when the call executes 原文 被defer的方法的参数,是在defer声明的时候就准备好的。如果方法带receiver,则receiver也是在defer声明的时候就准备好的。 例1: for i := 0; i < 5; i++ { defer fmt.Printf("%d ", i) } output: 4 3 2 1 0 例2: func trace(s string) string { f...阅读全文

博文 2020-03-24 22:32:44 舒小贱