标签归档:golang

golang的包管理工具

dep – Go dependency tool

Dep is a prototype dependency management tool. It requires Go 1.7 or newer to compile.

dep is NOT an official tool. Yet. Check out the Roadmap! Current status

Alpha. Functionality is known to be broken, missing or incomplete. Changes are planned to the CLI commands soon. It would be unwise to write scripts atop dep before then. The repository is open to solicit feedback and contributions from the community. Please see below for feedback and contribution guidelines.

Gopkg.toml and Gopkg.lock have reached a stable structure, and it is safe to commit them in your projects. We plan to add more to these files, but we guarantee these changes will be backwards-compatible.

glide – Package Management for Golang https://glide.sh

Are you used to tools such as Cargo, npm, Composer, Nuget, Pip, Maven, Bundler, or other modern package managers? If so, Glide is the comparable Go tool.

Manage your vendor and vendored packages with ease. Glide is a tool for managing the vendor directory within a Go package. This feature, first introduced in Go 1.5, allows each package to have a vendor directory containing dependent packages for the project. These vendor packages can be installed by a tool (e.g. glide), similar to go get or they can be vendored and distributed with the package.

Golang Dep

An official package manager has been started for the Go community. We view this as a good thing to bring everyone together around one solution. It’s currently pre-alpha so it’s not ready for prime time usage.

If you start to poke it you’ll see it has a similar style to Glide. While commands may have different names there are many of the same features such as semantic versions and ranges.

Our view is that Glide will be around until an official package manager is ready for production use by the masses. We support the common tool and look forward to the day it is capable of replacing Glide.

Features

  • Ease dependency management
  • Support versioning packages including Semantic Versioning 2.0.0 support. Any constraint the github.com/Masterminds/semver package can parse can be used.
  • Support aliasing packages (e.g. for working with github forks)
  • Remove the need for munging import statements
  • Work with all of the go tools
  • Support the VCS tools that Go supports:
    • git
    • bzr
    • hg
    • svn
  • Support custom local and global plugins (see docs/plugins.md)
  • Repository caching and data caching for improved performance.
  • Flatten dependencies resolving version differences and avoiding the inclusion of a package multiple times.
  • Manage and install dependencies on-demand or vendored in your version control system.

golang queue packages

github.com/rylio/queue

Execute tasks in parallel with a concurrency limit

github.com/bgentry/que-go

An interoperable Golang port of the Ruby Que queuing library for PostgreSQL

goworker

goworker is a Go-based background worker that runs 10 to 100,000* times faster than Ruby-based workers.

goworker is compatible with Resque, so you can push your jobs with Rails and Resque, and consume them with Go in the background.

machinery

Machinery is an asynchronous task queue/job queue based on distributed message passing.

golang通过web管理worker

Writing worker queues, in Go

Have you ever wanted to write something that is highly concurrent, and performs as many tasks as you will let it, in parallel? Well, look no further, here is a guide on how to do just that, in Go!

go-workers – Sidekiq compatible background workers in golang

Sidekiq compatible background workers in golang.

  • reliable queueing for all queues using brpoplpush
  • handles retries
  • support custom middleware
  • customize concurrency per queue
  • responds to Unix signals to safely wait for jobs to finish before exiting.
  • provides stats on what jobs are currently running
  • well tested

NSQ – A realtime distributed messaging platform

NSQ is a successor to simplequeue (part of simplehttp) and as such is designed to (in no particular order):

  • support topologies that enable high-availability and eliminate SPOFs
  • address the need for stronger message delivery guarantees
  • bound the memory footprint of a single process (by persisting some messages to disk)
  • greatly simplify configuration requirements for producers and consumers
  • provide a straightforward upgrade path
  • improve efficiency

Background Jobs with Que-Go

Web servers should focus on serving users as quickly as possible. Any non-trivial work that could slow down your user’s experience should be done asynchronously outside of the web process.

Worker queues are commonly used to accomplish this goal. For a more in-depth description of the worker queue architectural pattern, read the Worker Dynos, Background Jobs and Queueing article. Here we’ll demonstrate this pattern using a sample Go application using Que-Go and Heroku Postgres.

golang hello world

安装golang

下载

wget -c https://storage.googleapis.com/golang/go1.7.1.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.7.1.linux-amd64.tar.gz

vim ~/.bash_profile

export PATH=$PATH:/usr/local/go/bin

测试

go version  

设置gopath环境变量

mkdir ~/gocode
vim ~/.bash_profile

新增以下内容

export GOPATH=~/gocode
export PATH=$PATH:$GOPATH/bin

导入环境变量

source ~/.bash_profile

hello world

mkdir $GOPATH/bin 
mkdir $GOPATH/pkg 
mkdir $GOPATH/github.com/user/hello -p
cd $GOPATH/github.com/user/hello

vim hello.go

package main

import "fmt"

func main() {
        fmt.Printf("Hello, world.\n")
}

go build # 构建(可执行程序在$GOPATH/github.com/user/hello) go install # 安装(可执行程序在$GOPATH/bin) hello # 运行

Go的50度灰:Golang新开发者要注意的陷阱和常见错误

http://colobu.com/2015/09/07/gotchas-and-common-mistakes-in-go-golang/

原文: 50 Shades of Go: Traps, Gotchas, and Common Mistakes for New Golang Devs
翻译: Go的50度灰:新Golang开发者要注意的陷阱、技巧和常见错误, 译者: 影风LEY

Go是一门简单有趣的语言,但与其他语言类似,它会有一些技巧。。。这些技巧的绝大部分并不是Go的缺陷造成的。如果你以前使用的是其他语言,那么这其中的有些错误就是很自然的陷阱。其它的是由错误的假设和缺少细节造成的。

如果你花时间学习这门语言,阅读官方说明、wiki、邮件列表讨论、大量的优秀博文和Rob Pike的展示,以及源代码,这些技巧中的绝大多数都是显而易见的。尽管不是每个人都是以这种方式开始学习的,但也没关系。如果你是Go语言新人,那么这里的信息将会节约你大量的调试代码的时间。