随笔分类 -  go

聊聊GO-REDIS的一些高级用法
摘要:1. 前言 说到Golang的Redis库,用到最多的恐怕是redigo 和 go-redis。其中 redigo 不支持对集群的访问。本文想聊聊go-redis 2个高级用法 2. 开启对Cluster中Slave Node的访问 在一个负载比较高的Redis Cluster中,如果允许对slav 阅读全文

posted @ 2019-09-09 16:18 ExplorerMan 阅读(461) 评论(0) 推荐(0)

Golang- import 导入包的几种方式:点,别名与下划线
摘要:包的导入语法 在写Go代码的时候经常用到import这个命令用来导入包文件,看到的方式参考如下: import( "fmt" ) 然后在代码里面可以通过如下的方式调用 fmt.Println("hello world") 上面这个fmt是Go语言的标准库,他其实是去GOROOT下去加载该模块,当然G 阅读全文

posted @ 2019-09-09 11:36 ExplorerMan 阅读(11565) 评论(0) 推荐(1)

接口文档神器之apidoc
摘要://@desn:apidoc linux环境 windows环境使用 //@desn:码字不宜,转载请注明出处 //@author:张慧源 <turing_zhy@163.com> //@date:2018/5/6 正文: windows版安装: 1.安装nodejs (nodejs环境) 32 位 阅读全文

posted @ 2019-09-06 16:45 ExplorerMan 阅读(331) 评论(0) 推荐(0)

Golang 数组和切片
摘要:数组 数组是类型相同的元素的集合。例如,整数 5, 8, 9, 79, 76 的集合就构成了一个数组。Go不允许在数组中混合使用不同类型的元素(比如整数和字符串)。 声明 有很多声明数组的方式,让我们一个一个地介绍。 var a [3]int 声明了一个长度为 3 的整型数组。数组中的所有元素都被自 阅读全文

posted @ 2019-09-05 18:19 ExplorerMan 阅读(303) 评论(0) 推荐(0)

go切片展开
摘要:可以使用 ... 操作符将一个切片追加到另一个切片末尾: 上面的程序中,在第10行将 fruits 追加到 veggies 并赋值给 food。...操作符用来展开切片。程序的输出为:food: [potatoes tomatoes brinjal oranges apples]。 阅读全文

posted @ 2019-09-05 18:17 ExplorerMan 阅读(2064) 评论(0) 推荐(0)

Go的json解析:Marshal与Unmarshal
摘要:简介Json(Javascript Object Nanotation)是一种数据交换格式,常用于前后端数据传输。任意一端将数据转换成json 字符串,另一端再将该字符串解析成相应的数据结构,如string类型,strcut对象等。 go语言本身为我们提供了json的工具包”encoding/jso 阅读全文

posted @ 2019-09-04 19:42 ExplorerMan 阅读(545) 评论(0) 推荐(0)

golang depth read map
摘要:Foreword: I optimized and improved the below solution, and released it as a library here: github.com/icza/dyno. The cleanest way would be to create pr 阅读全文

posted @ 2019-09-04 19:32 ExplorerMan 阅读(410) 评论(0) 推荐(0)

golang 多级json转map
摘要:func main() { jsonStr := `{"isSchemaConforming":true,"schemaVersion":0,"unknown.0":[{"email_address":"test1@uber.com"},{"email_address":"test2@uber.com"}]}` dynamic := make(map[string]interf... 阅读全文

posted @ 2019-09-04 19:14 ExplorerMan 阅读(3309) 评论(0) 推荐(0)

GoLang中 json、map、struct 之间的相互转化
摘要:1. golang 中 json 转 struct <1. 使用 json.Unmarshal 时,结构体的每一项必须是导出项(import field)。也就是说结构体的 key 对应的首字母必须为大写。请看下面的例子: 输出的结果如下: 1 { 0} 1 { 0} 1 { 0} 1 { 0} { 阅读全文

posted @ 2019-09-04 19:06 ExplorerMan 阅读(686) 评论(0) 推荐(0)

利用delve(dlv)在Visual Code中进行go程序的远程调试-debug方式
摘要:最近碰到一个问题,如何在Windows的IDE或者文本编辑器上,远程调试Linux服务器上的golang程序。 虽然想说gdb走你,但既然go有dlv这样的类似Java的jdwp的原生方案,而且我用的Visual Code的官方Go插件支持这种方案,那就试一下这个方案吧。 2019-03-15追加: 阅读全文

posted @ 2019-09-04 17:46 ExplorerMan 阅读(1223) 评论(0) 推荐(0)

golang数据类型转换
摘要:int--string 1 2 3 4 //string到int value_int,err:=strconv.Atoi(string) //int到string str:=strconv.Itoa(value_int) 1 2 3 4 //string到int value_int,err:=str 阅读全文

posted @ 2019-09-04 16:00 ExplorerMan 阅读(165) 评论(0) 推荐(0)

golang 数据类型之间的转换
摘要:一、基本数据类型之间的转换 1、string到int int,err:=strconv.Atoi(string) 2、string到int64 int64, err := strconv.ParseInt(string, 10, 64) 3、int到string string:=strconv.It 阅读全文

posted @ 2019-09-04 15:57 ExplorerMan 阅读(900) 评论(0) 推荐(0)

Golang中用interface{}接收任何参数与强转
摘要:函数的传值中,interface{}是可以传任意参数的,就像java的object那样。下面上我第一次想当然写的 ** 错误 **代码 我只是想它能通过编译而已,因为上面的错误代码并没有任何的语法错误,心里只有666想说,下面是编译的错误提示:cannot convert v (type inter 阅读全文

posted @ 2019-09-04 15:29 ExplorerMan 阅读(787) 评论(1) 推荐(0)

beego 如何自定error
摘要:beego通过Redirect方法来进行跳转: 1 2 3 func (this *AddController) Get() { this.Redirect("/", 302) } 1 2 3 func (this *AddController) Get() { this.Redirect("/", 阅读全文

posted @ 2019-09-03 21:40 ExplorerMan 阅读(936) 评论(0) 推荐(0)

golang struct结构体初始化的几种方式
摘要:type User struct { Id int `json:"id" orm:"auto"` // 用户名 Username string `json:"username"`} func main() { //值类型 u1:=models.User{} var u2 models.User // 阅读全文

posted @ 2019-09-03 18:32 ExplorerMan 阅读(2911) 评论(0) 推荐(0)

golang单例模式
摘要:1、定义:单例对象的类必须保证只有一个实例存在,全局有唯一接口访问。 2、分类: 懒汉方式:指全局的单例实例在第一次被使用时构建。 饿汉方式:指全局的单例实例在类装载时构建。 3、实现: (1)懒汉方式 缺点:非线程安全。当正在创建时,有线程来访问此时ins = nil就会再创建,单例类就会有多个实 阅读全文

posted @ 2019-09-03 18:25 ExplorerMan 阅读(303) 评论(0) 推荐(0)

Golang 单例模式 singleton pattern
摘要:在Java中,单例模式的实现主要依靠类中的静态字段。在Go语言中,没有静态类成员,所以我们使用的包访问机制和函数来提供类似的功能。来看下下面的例子: package singleton import ( "fmt") type Singleton interface { SaySomething() 阅读全文

posted @ 2019-09-03 16:47 ExplorerMan 阅读(435) 评论(0) 推荐(0)

golang可见性规则(公有与私有,访问权限)
摘要:Go语言没有像其它语言一样有public、protected、private等访问控制修饰符,它是通过字母大小写来控制可见性的,如果定义的常量、变量、类型、接口、结构、函数等的名称是大写字母开头表示能被其它包访问或调用(相当于public),非大写开头就只能在包内使用(相当于private,变量或常 阅读全文

posted @ 2019-09-03 14:29 ExplorerMan 阅读(2385) 评论(0) 推荐(0)

golang init方法和main方法初始化顺序
摘要:init()和main()方法是golang默认的两个方法,不需要我们调用,程序执行会自动寻找项目中的这俩方法。现在我们就讲一种通用的情况:main 包下 导入了 init2 包而在init2 包下又导入了init3 包,三个包下都有自己的init 方法,初始化的顺序又是怎么的呢?先看一段代码: 程 阅读全文

posted @ 2019-09-03 14:17 ExplorerMan 阅读(651) 评论(0) 推荐(0)

Golang的面向对象编程【结构体、方法、继承、接口】
摘要:Golang也支持面向对象编程。但与以前学过传统的面向对象编程语言有区别。1)Golang没有类class,Go语言的结构体struct和类class有相似的特性。2)Golang中不存在继承,方法重载,构造函数,析构函数,隐藏和this指针。3)Golang有继承,封装,多态的特性,但是实现方法与 阅读全文

posted @ 2019-09-03 13:24 ExplorerMan 阅读(851) 评论(0) 推荐(0)

导航