Any consequences to wrapping simple data types in a struct?
<p>Here's the scenario: I'm defining an type for a function that I want to pass into another function. This type is called Worker. Currently, a Worker function accepts a single argument that is a byte slice.</p> <p>Now, as we know, thing change over time, so I'm thinking that if I create a new type that,...阅读全文
In about 10 years, Fidget Spinners will be part of "Only 2000s Kids Will Remember" posts.
<hr/>**评论:**<br/><br/>Jashua_JH: <pre><p>You mean 2010s kids.</p></pre>hogger85: <pre><p>probably those born between 2002 and 2013 will be generation fidget spinner.</p></pre>ithrewakidinthewell: <pre><p>Can confirm, was born in 2000. Anyone in my year who owns one has be...阅读全文
Keep state over multiple instances
<p>TL;DR Looking for a way too share state over cluster without database </p> <p>Sup. Im trying to build a highload service (its kinda pet ) and it should take about 300-500 requests per second. Its should keep in RAM about 500-700Mb stack of text lines (in bytes i guess), return one line by request and iterate to a next one. (go...阅读全文
前端工程师吐后端工程师(第九讲)——最不擅长的数据库操作
第八讲中我们介绍了如果使用Gin写一些常用的接口,本讲我们主要介绍一下数据库如何操作。这一讲没有具体页面,可能对于前端工程师会不太习惯。首先我们要单件一个mysql数据库环境。如果不会的话可以参考这个教程https://www.jianshu.com/p/3a0de5da49f3,在搭建完成MySQL,并且启动MySQL之后。数据的管理员账户名设置成root,数据库密码设置为00000000。因为后续我们在代码中使用的数据库相关代码,会以这个为准.我们可以通过mysql -h 127.0.0.1 -P 3306 -u root -p 000000000 指令来连接刚刚搭建在本机上的数据库。127.0.0.1为本机IP,3306为数据库具体端口,root为数据库用户名,000000000为数据...阅读全文
What movie should never have been made?
<hr/>**评论:**<br/><br/>Jevin1983: <pre><p>The Mask 2, son of mask.</p></pre>Captain_Kuhl: <pre><p>That movie made me legitimately mad when I saw it for the first time. The Mask was so damn good, and then they make <em>that</em>? It's like they ripped off their own leg to step...阅读全文
The price of movies should be variable based on demand (like stock). e.g.: King Arthur is flopping? Tickets are $2.99.
<hr/>**评论:**<br/><br/>Philinhere: <pre><p>Star Wars: Episode 8</p> <p>Only $44.99!</p></pre>PointOfFingers: <pre><p>But you get $5 off if you have a ticket stub for Episode 1.</p></pre>ChefLev: <pre><p>Talk about an appreciating asset. </p></pre>cr...阅读全文
Progress checking for goroutines workers?
<p>This is probably not a Go specific question, but currently I am trying to display the progress for each goroutine worker in the frontend. The individual task is mainly calling external APIs and process those data into a database.</p> <p>What would be the general approach to implement such feature?</p> <hr/>**评论:**&...阅读全文
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...阅读全文
quick check proxy list from a file
<p>Hello! I think it's will be useful for quickly checking and verify your proxy list from a file. I'm also available for any suggestion. <a href="https://github.com/asm-jaime/go-proxycheck" rel="nofollow">https://github.com/asm-jaime/go-proxycheck</a></p> <hr/>**评论:**<br/><br/&...阅读全文
Performance difference for unmarshaling json between struct and map?
<p>I am trying to parse a json object from a http response.</p> <p>The first method I tried was not defining the structure:</p> <pre><code>type Users []map[string]string var users Users </code></pre> <p>Which surprisingly outperforms the method that defines the structure:</p> <pre&g...阅读全文
Graphqlator - A CLI program that generates a graphql-go server from an existing MySQL, MariaDB, or PostgresQL schema
<p>Hello Gophers,</p> <p>I'm new here, been mostly lurking for the past few months. I've written an open-source CLI tool that generates a GraphQL API server.</p> <p>It does this by connecting to your database instance and querying the <a href="https://dev.mysql.com/doc/refman/5.7/en/information...阅读全文
The "VTable pattern" in Go
<p>I know I am not supposed to think about virtual functions when programming in Go. :> However, recently I noticed that there is a "code reuse via dynamic dispatch" pattern lurking in some of my projects anyway, and so I took some time to extract it into a demo project to help myself re-execute the pattern should the n...阅读全文
What pointer is for?
<p>Start with C++ for about a months then move entirely to C# and since the language I'm dealing with doesn't have pointer (Javascript, Python, PHP....) I really don't know the point of pointer. Now I'm learning Go because I want to program a distribute network. I searched for what is pointer and the answer doe...阅读全文
Go 语言学习笔记 -第4章复合数据类型
Go 语言学习笔记 -第4章 [toc] 复合数据类型 数组 Golang中操作数组或者序列化数据需要用到slice,程序中写作“[]" slice 指向数组的值,并且同时包含了长度信息 package main import "fmt" func main() { // list := []int{1, 2, 3, 4} list := [...]int{1, 2, 3, 4} fmt.Println(list) fmt.Printf("Type %T\n", list) for i := 0; i < len(list); i++ { fmt.Printf("list[%d]=%d\n", i, list[i]) } //重新切片s[low:high], low->(high-1) fm...阅读全文
Docker基础(2) 实践篇
Docker基础(2) 实践篇 Docker的指令系统 全局指令 Docker仓库管理 Docker镜像管理 Dockerfile Docker容器管理 Docker Compose 命令的嵌套 Docker的指令系统 Docker指令的操作对象主要针对四个方面: 针对守护进程的系统资源设置和全局信息的获取。比如:docker info、docker deamon等。 针对Docker仓库的查询、下载操作。比如:docker search、docker pull等。 针对Docker镜像的查询、创建、删除操作。比如:docker images、docker build等。 针对Docker容器的查询、创建、开启、停止操作。比如:docker ps、docker run、docker star...阅读全文
Auto-generating proxy objects
<p>So I'm trying to generate proxy objects to wrap some existing objects. I'd like to create proxies which add logging without having to write the logging in to each of my objects and method calls.</p> <p>I know I can do this by writing a proxy myself, but I have a lot of objects that I don't want to chan...阅读全文
Newbie developer looking for advice
<p>Hi there, so quick background: I know a little bit of a lot of languages, and I'm currently waiting for course results before choosing a career path. I do primarily web technologies. </p> <p>I've been looking at golang as an upcoming language I think will be huge, but I'm not really seeing a purpose for...阅读全文
Where is the canonical place to keep HTML/Templates/JS files?
<p>Assuming you're using the <a href="https://golang.org/doc/code.html#Workspaces">canonical</a> workspace layout, you keep your projects under $GOHOME/src/$YourGitHost/$YourProjectName, and it will install into $GOHOME/bin/YouProjectName.</p> <p>But what about a webapp? Do you just keep it as a subdir...阅读全文
What packages/interfaces in the standard library should I study first?
<p>io and io/ioutil and the reader/writer interfaces look like they come up often, what else?</p> <hr/>**评论:**<br/><br/>nerr: <pre><p>net/http for high level interfaces, net for high level abstractions over low level interfaces.</p></pre>hanmunjae: <pre><p>time: commonly used. Surpri...阅读全文
[ANN] legume, a minimalist distributed issue tracking system following todo.txt philosophy.
<p>I was inspired by lentil, a tool that uses developer TODO & FIXME comments as a sort of issue tracker. I had a couple of issues with lentil that prompted me to rewrite it in Go.</p> <p><a href="https://asciinema.org/a/47ywzgoax4ybtf18dywwkyur7">Here's a screen cast</a></p> <p>B...阅读全文
重新认识Go的Slice
开篇语 大多数时候我们都忘记了或者压根不知道slice是怎么工作的。大多数时候我们只是把slice当做动态数组来用。通过重新认识slice,我们可以一定程度上避免掉入slice的陷阱,并且更好的使用它。 参考资料有: Effective Go Go Slices: usage and internal 本文重点是代码例子,边动手边学习 回归本元: 什么是数组? Go中的数组(array)是一个固定大小的、单一类型的一个序列。 创建数组需要两个参数:size和type。 Array的size是类型的一部分 x := [5]int{1, 2, 3} y := [5]int{3, 2, 1} z := [5]int{1, 2, 3} fmt.Printf("x == y: %v\\n", x ==...阅读全文
Is it idiomatic to return a badly structured object together with error?
<p>Suppose I have a method that does some work and than returns the result and an error: </p> <pre><code>type Res struct { // some fields } func foo() (Res, error) { res := Res{ // some initialization } err := DoSomeWork(&res) if err != nil { return nil, err } return res, er...阅读全文
Constructor returning a pointer (noob question)
<p>Is it idiomatic for a constructor to return a pointer to a newly created struct? Or does it depend on the size of the newly constructed struct? Most examples I see return a pointer but I don't know why.</p> <hr/>**评论:**<br/><br/>Sythe2o0: <pre><p>It depends on the use case. Do you want the method...阅读全文
What is the idiomatic way to consolidate sql queries in golang?
<p>I am working on a project that is growing in terms of the amount of people working on it and the amount of different queries we have to support. It seems people are just writing more and more separate queries. Although I am only a junior developer, I can foresee this becoming hard to maintain. What is usually the idiomatic way of consolida...阅读全文
Detect a line in a file and then edit it
<p>Hi everyone, </p> <p>I'm trying to go through a file through a Scanner or a Reader line by line, then check if each line matches a certain pattern. </p> <p>Once this is done, I'd like to record the position of the line to edit it, but file.Seek(0,1) doesn't work well, as Scanner and Reader ...阅读全文