常用 package

Go 常用 package #

net #

imroc/req

Github stars #

Go 语言人性化 HTTP 请求库

valyala/fasthttp

Github stars #

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http


cmd #

spf13/cobra

Github stars #

A Commander for modern Go CLI interactions

quick start #

typically a Cobra-based application will follow the following organizational structure:

  ▾ appName/
    ▾ cmd/
        add.go
        your.go
        commands.go
        here.go
      main.go

In a Cobra app, typically the main.go file is very bare. It serves one purpose: initializing Cobra.

package main

import (
  "{pathToYourApp}/cmd"
)

func main() {
  cmd.Execute()
}

Ideally you place this in app/cmd/root.go:

var rootCmd = &cobra.Command{
  Use:   "hugo",
  Short: "Hugo is a very fast static site generator",
  Long: `A Fast and Flexible Static Site Generator built with
                love by spf13 and friends in Go.
                Complete documentation is available at http://hugo.spf13.com`,
  Run: func(cmd *cobra.Command, args []string) {
    // 在这里写应用逻辑
  },
}

func Execute() {
  if err := rootCmd.Execute(); err != nil {
    fmt.Println(err)
    os.Exit(1)
  }
}

web #

gorilla/mux

Github stars #

A powerful HTTP router and URL matcher for building Go web servers

githubnemo/CompileDaemon

Github stars #

Watches your .go files in a directory and invokes go build if a file changed.

Usage:

./CompileDaemon -directory=yourproject/

其他 #

fsnotify/fsnotify

Github stars #

Cross-platform file system notifications for Go.

gomodule/redigo

Github stars #

Go client for Redis

go-redis/redis

Github stars #

Type-safe Redis client for Golang

https://godoc.org/github.com/go-redis/redis

spf13/afero

Github stars #

A FileSystem Abstraction System for Go