Learning Go! Would appreciate some criticism of this microservice
<p>It's super simple: It queuries alphavantage for given stocks, and exposes it on a REST api.</p> <p>It uses a JWT from Firebase users linked to the project to validate queuries, and it can be automatically deployed to Google Cloud App Engine. It does a lot of things in that small amount of code, I think.</p> <...阅读全文
老虞学GoLang笔记-变量声明与初始化
开发十年,就只剩下这套Java开发体系了 >>> 变量声明 官方DOC: http://golang.org//spec#Variable_declarations Go中使用全新的关键字var来声明变量。var我们并不陌生,在Javascript 和C#中均有出现。不同的是Go和C#中变量属于强类型,在声明变量后就不允许改变其数据类型。 声明变量有多种形态: var a int //声明一个int类型的变量 var b struct { //声明一个结构体 name string } var a = 8 //声明变量的同时赋值,编译器自动推导其数据类型 var a int = 8 //声明变量的同时赋值 var { //批量声明变量,简洁 a int b string } 变量初始化 变量...阅读全文
nginx学习笔记
中间件位于客户机/ 服务器的操作系统之上,管理计算机资源和网络通讯。 是连接两个独立应用程序或独立系统的软件。 web请求通过中间件可以直接调用操作系统,也可以经过中间件把请求分发到多个应用上进行逻辑处理。 因为有了中间件,使得大型网站在规划有了更好的层次性,维护上更加方便。也可以实现负载均衡、安全防护等。 Nginx是一个开源高性能、可靠的HTTP中间件、代理服务,在目前企业中得到了很大的利用。 今天主要学习下nginx的安装配置,以便于后续学习。 以下在本地虚拟机上搭建学习。 linux环境搭建可以参考: vmware上安装linux过程记录 1、 检查系统网络是否能连通公网: ping www.taobao.com 2、 确认yum源是否配置好,用于下载安装环境基础包: yum源配置可...阅读全文
Why do you want to use Go and not something else?
<p>I came across these articles by Dave Cheney this morning entitled <a href="https://dave.cheney.net/2017/06/15/simplicity-debt">Simplicity Debt</a> and <a href="https://dave.cheney.net/2017/06/18/simplicity-debt-redux">Simplicity Debt Redux</a>. </p> <p>Dave makes an argument for generics...阅读全文
[Go 教程系列笔记]结构而不是类-Go中的OOP
Go 教程系列笔记 Interface 第一部分 Go 教程系列笔记 Interface 第二部分 Go 教程系列笔记 并发介绍 Go 教程系列笔记 goroutine(协程) Go 教程系列笔记 Channel 通道 Go 教程系列笔记 缓冲通道和工作池 Go 教程系列笔记 Select Go 教程系列笔记 Mutex(互斥锁) Go 教程系列笔记 结构而不是类-Go中的OOP Go 教程系列笔记 组合而不是继承-Go 中的 OOP Go 教程系列笔记 多态-Go 中的 OOP Go 面向对象? Go 不是纯粹的面向对象编程语言。摘自Go的常见问题解答,回答了Go是否面向对象的问题。 Yes and no. Although Go has types and methods and all...阅读全文
New to Golang
<p>I'm wanting to learn golang, I haven't programmed anything in a while. Probably C++ and java 6 years ago. So I was wondering what suggestions you have to learn it better. </p> <p>I would like to try and be hands on with it. I've done the tour of go, and read a bunch about it, but I feel like I won&#...阅读全文
How do we debug what went in wrong in the libraries that we use with "return error instead of throwing exception" model?
<p>I'm faced with a little challenge today. I'm using a library which ultimately uses sycalls to do the stuff. If a syscall fails, it returns with an error obtained from the syscall itself. As these errors come from the native apis (like winapi?), they are sometimes generic (like system cannot find path specified). If they ar...阅读全文
A question about generics
<p>(I posted this in an ironic sub, but I think the question is worth being asked) </p> <p>I'm sure this debate has been had a trillion times by now, but how are generics necessary for reusability when we have interfaces. A reusable sort for instance, would just require the members of the input list to implement an ICompa...阅读全文
What if go had something like Java's Annotation Processor for code generation?
<p>I think go generate is awesome, specially when combined of other toolkit goodnesses, like build tags, awesome community tools and external build tools. </p> <p>But it has its drawbacks, and it imposes some workflow restrictions that make it not always a desirable solution. </p> <p>The main problem being it doesn&a...阅读全文
要获得中间件开发的Offer,难么?
# 前言本文主要是写给那些想从事中间件开发的同学看的 :)如果你没有这个打算,那么本文的学习路线非但不实用,还可能会影响你正常的工作 :)# 什么是中间件开发?随着国内软件行业的发展,国内互联网公司规模越来越大,业务越来越复杂,随之使用大量的中间件来提高后台服务性能。由此产生了中间件开发和维护人员。诚然,在小公司,中间件,例如缓存,MQ,RPC 等服务,极大可能是由业务开发人员自己维护,或者委托第三方云平台运维(支付一些费用)。但,如果后台开发超过 200 人,基本就会组建自己的中间件或者基础架构团队,用于维护后台服务器基础架构和中间件。更大规模的公司,则由于各种各样的原因(性能,KPI),会自己开发中间件,简称自研。这要求中间件团队需要更多的人员。# 中间件开发人员需要哪些素质?既然需要中...阅读全文
Help me with a Reddit bot in Go!
<p>Hey guys! I'm trying to build a bot for Reddit written in Go so I can learn a new language, etc etc.</p> <p>However some questions arose:</p> <p>-Best way to separate files, implementations, functions and so on. I have a Java background, as you know in Java, one class, one file and so on, however in Go it ...阅读全文
Any Go Mobile Devs?
<p>There used to be some noise around Go Mobile but unfortunatley the winds have calmed now for over a year. Is anyone here familiar with writing mobile cross-plattform Go Apps (or libraries)?</p> <p>I'm a former Android Dev and I have been looking out for technologies to write cross-plattform code and wiring it later to...阅读全文
Learning Go, making a package, unsure how to initialise the package with a string from the code using the package?
<p>I'm very very new to Golang and I'm making a basic package that will do some mutations to a collection of strings when you call the methods.</p> <p>I'm currently using ioutil.ReadFile in the package to read a text file, I then transform it into my struct that makes it easier to work with then I assign i...阅读全文
Why isn't there a Logger interface in the standard library?
<p>Just curious why the log package does not expose an interface for logging allowing us to implement custom logging logic with a standard interface.</p> <hr/>**评论:**<br/><br/>kardianos: <pre><p>No one seems to be able to agree what such an interface should look like. There was a golang-dev thread about jus...阅读全文
newbe question regarding the use of anonymous fields, Why do you use them?
<p>I came across this <a href="http://golangtutorials.blogspot.com/2011/06/anonymous-fields-in-structs-like-object.html" rel="nofollow">blog post on anonymous fields</a> </p> <p>I'm a bit confused as to why would want to use an anonymous field as opposed to declaring a name with the type. </...阅读全文
if int and int32 the same, why golang keeps these two?
<p>tbh, this raises confusing if you were programming in java or cpp</p> <hr/>**评论:**<br/><br/>iroflmaowtf: <pre><p><a href="https://golang.org/pkg/builtin/#int" rel="nofollow">https://golang.org/pkg/builtin/#int</a></p> <blockquote> <p>int is a signed integer t...阅读全文
Go面向对象编程以及在Tendermint/Cosmos-SDK中的应用
Go面向对象编程以及在Tendermint/Cosmos-SDK中的应用 大家都知道,Go不是面向对象(Object Oriented,后面简称为OO)语言。本文以Java语言为例,介绍传统OO编程拥有的特性,以及在Go语言中如何模拟这些特性。文中出现的示例代码都取自Cosmos-SDK或Tendermint源代码。以下是本文将要介绍的OO编程的主要概念: 类(Class) 字段(Field) 实例字段 类字段 方法(Method) 实例方法 类方法 构造函数(Constructor) 信息隐藏 继承 利斯科夫替换原则(Liskov Substitution Principle,LSP) 方法重写(Overriding) 方法重载(Overloading) 多态 接口(Interface) ...阅读全文
687.最长同路径值
题目描述 给定一个二叉树,找到最长的路径,这个路径中的每个节点具有相同值。 这条路径可以经过也可以不经过根节点。 注意:两个节点之间的路径长度由它们之间的边数表示。 示例 输入: 5 / \ 4 5 / \ \ 1 1 5 输出: 2 思路 1.可以根据题意推导出本题的公式:rootPathVal = Math.max(leftPathVal,rightPathVal)。 2.可以看出此题可以使用递归思想求解。 3.若leftVal == rootVal,则leftPathVal = leftPathVal + 1,否则leftVal = 0 ,因为只有相同时,leftVal才可以作为同路径的参考;rightVal也是同理。 Java代码实现 class Solution { private...阅读全文
Learning Go as a Polyglot Developer
<p>Hi all. I've written a good deal of code in Python, C, C#, Java, and Rust, and I'm having kind of a hard time with Go. It might be that I've been spending too much time in Rust, but for a compiled language, it seems like Go's type system is insufficiently expressive, what with the lack of either generics or ...阅读全文
MaxCompute与OSS非结构化数据读写互通(及图像处理实例)
摘要: MaxCompute作为阿里巴巴集团内部绝大多数大数据处理需求的核心计算组件,拥有强大的计算能力,随着集团内外大数据业务的不断扩展,新的数据使用场景也在不断产生。在这样的背景下,MaxCompute(ODPS)计算框架持续演化,而原来主要面对内部特殊格式数据的强大计算能力,也正在一步步的通过新增的非结构化数据处理框架,开放给不同的外部数据。 **0\. 前言** MaxCompute作为阿里巴巴集团内部绝大多数大数据处理需求的核心计算组件,拥有强大的计算能力,随着集团内外大数据业务的不断扩展,新的数据使用场景也在不断产生。在这样的背景下,MaxCompute(ODPS)计算框架持续演化,而原来主要面对内部特殊格式数据的强大计算能力,也正在一步步的通过新增的非结构化数据处理...阅读全文
What libraries would you like to see implemented in Go?
<p>I'm looking for ideas for libraries that I could implement in Go for the benefit of the community and for my own learning experience.</p> <hr/>**评论:**<br/><br/>andradei: <pre><p>Native GUI libs</p></pre>natefinch: <pre><p>AFAIK we're still missing a code highlighti...阅读全文
is marshaling the same as serializing ?
<hr/>**评论:**<br/><br/>tv64738: <pre><p>It's been called serializing, too. Marshaling is nicer as a name, because these days, serializing often means ordering events in a (distributed) system.</p></pre>: <pre><p>[deleted]</p></pre>eid-a: <pre><p>So ? I've r...阅读全文
What "mature" Go libraries/frameworks are available that companies can put their trust in?
<p>If you were the CTO of a medium-sized technology company and you have decided to use Go as your company's main programming language, which libraries or frameworks would you encourage your team(s) to use? Please base it on the knowledge that these libraries are proven to work well for production-code, their authors won't dis...阅读全文
Go学习笔记-面向对象struct成员变量
结构体`struct`可以用来描述一组数据值,这组值的本质即可以是原始的,也可以是非原始的。是用户自定义的类型,它代表若干字段的集合,可以用于描述一个实体对象,类似`java`,`php`中的`class`,是`golang`面向对象编程的基础类型。 今天我们先来看看`golang`中的成员变量的实现。 >基本的属性(成员变量) ``` type Teacher struct { Name string age int Sex string } func Create() Teacher { cang := Teacher{Name:"teacher cang",age:20,Sex:"woman"} return cang } ``` 对于在上面结构体`teacher`其实我们可以把它看成...阅读全文
572. 另一个树的子树
题目描述 给定两个非空二叉树 s 和 t,检验 s 中是否包含和 t 具有相同结构和节点值的子树。s 的一个子树包括 s 的一个节点和这个节点的所有子孙。s 也可以看做它自身的一棵子树。 示例 给定的树 s: 3 / \ 4 5 / \ 1 2 给定的树 t: 4 / \ 1 2 返回 true,因为 t 与 s 的一个子树拥有相同的结构和节点值。 思路 1.递归比较两个数的结构。 2.比较A树和B树当前的结点,若A树和B树的值相等,则继续比较它们的左右子树;若不相等,则拿A树的左子树和右子树进行同样的过程。 3.当A树和B树同时遍历到了空结点,说明B是A的子结构;否则不是A的子结构。 Java代码实现 class Solution { public boolean isSubtree(Tr...阅读全文
would generics help C# developers move to Go?
<p>I'm a .net developer and want to use Go for microservices for two reasons, single binary and better performance. Recently, someone made a good case to stay with C#. <a href="https://youtu.be/8qjNy8p_TnY?t=16m31s" rel="nofollow">https://youtu.be/8qjNy8p_TnY?t=16m31s</a> </p> <p>tldr; .n...阅读全文
Junior developer, should I learn go?
<p>Hey everyone, great community first of all. Creating this thread to ask a career question (sorry if it sounds like a stupid question). </p> <p>I'm currently a junior developer that knows a bit of python and javascript (I use node + jquery/react at work). Go is on my list of languages to learn but I don't know w...阅读全文
Question: design issue and idiomatic go
<p>I currently have a client for a system that can do:</p> <ul> <li>fetch (a set of messages)</li> <li>ack (a single message with ok or error)</li> <li>ackall (all messages, only ok at this time)</li> </ul> <p>On top of this i will build a listener, a background process that will f...阅读全文
第五章 九析带你轻松完爆 go - 字符串操作
目录1 前言2 字符串操作 2.1 字符串声明与赋值 2.2 字符串长度 2.3 字符串轮询 2.4 字符串中字符替换1 前言 如果你对博客有任何疑问或者想更深入学习 go,请加微信群,我们一起进步:2 字符串操作2.1 字符串声明与赋值 字符串声明和赋值使用 := 操作符。代码如下:package mainimport "fmt"func main() { s := "hello jiuxi" fmt.Println(s)}2.2 字符串长度 获取字符串长度可以使用函数 len()。但是英文字符和中文字符 len() 的处理结果不同,英文字符长度为 1,中文字符长度为 3。代码如下:package mainimport "fmt"func main() { enStr := "h" cnS...阅读全文
Go in enterprise environments
<p>I am curious how do you people work with Go in an enterprise environments when you often need to talk to unknown (often shitty) SOAP endpoints or consume messages from proprietary MQs etc. How do you deal with it ?</p> <hr/>**评论:**<br/><br/>egonelbre: <pre><p>It really doesn't differ much from ot...阅读全文
和为S的两个数字
题目描述 输入一个递增排序的数组和一个数字S,在数组中查找两个数,使得他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的。 示例: 输入:target = 9 输出:[[2,3,4],[4,5]] 思路 1.这道题可以使用“双指针”的思想解决。 2.设置两个指针,分别指向首位两个元素。 当nums[low]+nums[high]==target时,返回双指针对应的数字 当 nums [ low] > target - nums [ high] 时,说明右边的值过大,high- 1 当 nums [ low] < target - nums [ high] 时,说明左边的值过小,low+ 1 Java代码实现 public class Solution { public int...阅读全文
The conventional FizzBuzz problem in go Lang using Maps.
<p>I am learning go and was curious on how to use go maps to solve the conventional fizzbuzz problem, i.e. print number from say, 1-100 and multiples of 3 & 5 get printed fizz and buzz respectively. I looked over a bunch of solutions in different languages but somehow can't produce the same results in go. Thanks in advance.<...阅读全文
What advantages does Go have over Haskell?
<p>If Haskell is hard to learn, and Go is much easier to learn, especially for programmers experienced with C, C++, Java, Python, etc., is that alone a good enough reason to prefer Go over Haskell? Or are there other, better, reasons to take into account, when making such decisions?</p> <hr/>**评论:**<br/><br/>Shonucic:...阅读全文
How damaging for the Golang community is docker becoming pay-to-use ? Will this become a trend ?
<p>First of all, I understand that the "old docker" is still alive in the form of moby. However, the "owners" of docker have chosen to use the brand of docker for a closed "EE" product.</p> <p>This is obviously bad because it splits the community. People will fork away from Moby bec...阅读全文
quick question; why pointer?
<p>I'm coming from Java, and pointers are really not my strong side. So please bear with me. I'm following a simple tutorial, and I've noticed this code:</p> <p>//Page is a struct defined earlier</p> <p>func (p *Page) save() error { filename := p.Title + ".txt" return i...阅读全文
Go学习笔记-面向对象struct成员变量
结构体struct可以用来描述一组数据值,这组值的本质即可以是原始的,也可以是非原始的。是用户自定义的类型,它代表若干字段的集合,可以用于描述一个实体对象,类似java,php中的class,是golang面向对象编程的基础类型。 今天我们先来看看golang中的成员变量的实现。 基本的属性(成员变量) type Teacher struct { Name string age int Sex string } func Create() Teacher { cang := Teacher{Name:"teacher cang",age:20,Sex:"woman"} return cang } 对于在上面结构体teacher其实我们可以把它看成一个class而Name,Sex是可以被外部(...阅读全文
5大最新云原生镜像构建工具全解析,3个来自Google,你了解几个?
1云原生大背景下的镜像构建在分享开始,我想先跟大家简单聊一下云原生,可能不会详细展开,而是带领大家了解一下云原生对镜像构建方面的影响。第一,在接触云原生相关的技术时,无论是要解决开发、测试环境的问题,还是解决日常开发、测试等相关的操作和流程,我们经常都会谈到持续集成。持续集成首先要做代码的集成,不同的feature一起交付,使用持续集成的理念尽快把代码合并,保证代码没有冲突,这是持续集成最简单的一些理念。在持续集成之后,要考虑做哪些业务的验证。验证之外,还需要有一些安全相关的策略。比如,在开发过程中是否使用了不安全的代码或依赖包。在构建的过程中,还要生产许多不同的制品。那么问题就来了,云原生技术确实能通过容器化、K8s集群编排等提供能够复制的应用环境。无论什么语言,Java或Python等都...阅读全文
Leetcode 876. Middle of the Linked List
Given a non-empty, singly linked list with head node head, return a middle node of linked list. If there are two middle nodes, return the second middle node. Example 1: Input: [1,2,3,4,5] Output: Node 3 from this list (Serialization: [3,4,5]) The returned node has value 3. (The judge's serialization of this node is [3,4,5]). Note that we returned a...阅读全文
LeetCode1.两数之和
问题描述: 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。 示例: 给定 nums = [2, 7, 11, 15], target = 9因为 nums[0] + nums[1] = 2 + 7 = 9所以返回 [0, 1] 解题思路: 1.暴力法 利用两层循环查找和为目标值的两个整数,并返回下标。 2.HashMap两层循环 先将数组中的值和下标作为key和value存到HashMap中,然后遍历数组,计算差值是否在HashMap中,若存在,返回对应两个目标值的下标。 注意:有缺陷,对于数组中存在相同元素,得到的下标,有问题。例如[3...阅读全文
What are some good recourses to learn go for someone who knows java/c#/python quite well
<p>Title</p> <hr/>**评论:**<br/><br/>OhGodNotHimAgain: <pre><p>I've just used <a href="https://gobyexample.com" rel="nofollow">https://gobyexample.com</a></p></pre>: <pre><p>[deleted]</p></pre>senteswins: <pre><p>Oh didn&#...阅读全文
Github架构师解读C/C++应用包管理的Why和How
一、背景本文整理自Johannes Nicolai在JFrog 2019用户大会上的讲演《DevOps for Non-Hipsters(aka C/C++ programmers)》。Johannes Nicolai是Github的解决方案架构师,主要负责德语区的用户。他和很多制造业的用户(多数使用C/C++)交流,询问他们在DevOps或持续交付方面的挑战,通常会得到如下的描述:在嵌入式C/C++领域,花费几十个小时完成一个完整的DevOps流水线并不少见。为某一个提交运行单独的构建和测试几乎是不可能的,通常每次构建都包含了几百个同事所有的提交。而构建时间长的主要原因在于交付包包含了大量的依赖包,而每次构建这些依赖包都需要从头开始重新构建。上述的描述并不仅限于德语区,Johannes...阅读全文
Whats the benefit of composition/encapsulation over inheritance?
<p>After using go for a bit I'm not seeing the obvious benefit of encapsulation. Is it that encapsulation covers the errors of not having multi-inheritance in most OO languages. And if that's the reason, can one just create a linear subclass list in the OO language if that effect was ever needed?</p> <hr/>**评论:**&l...阅读全文