golang-区块链学习03永久存储
前言 前面两篇简单的实现了区块链的创建和工作量证明,但是都是在内存中进行的。实际的区块链应该是可以永久存储的,这样才有意义。下面开始做永久性区块链存储。 知识点 1、github项目引用 2、github.com/boltdb/bolt项目的简单使用 3、命令行使用 4、go常用的数据转换 golang-区块链永久性存储 1、创建区块链 方法:func NewBlockChain() *BlockChain // 创建区块链 // 返回一个区块链实例 func NewBlockChain() *BlockChain { var tip []byte // 打开存储区块链的文件blockchian.db、不存在则创建 db, err := bolt.Open(dbFile, 0600, nil...阅读全文
Noopher: Is there any good resource for learning about Writer and Reader?
<p>A noob gopher here. It seems that Reader and Writer are a huge part of golang language. Especially when it comes to terminal user input. However, coming from (very basic) Python, user interaction through terminal is giving me headaches. And the Reader/Writer interfaces are right in the middle of all of this.</p> <p>So far I&am...阅读全文
statelessPassword: a password manager that doesn't store your passwords (Feedback appreciated)
<p><a href="https://go.iondynamics.net/statelessPassword">statelessPassword</a> is a derivation of <a href="https://en.wikipedia.org/wiki/Master_Password">Billemont's master password algorithm</a></p> <p>It comes with a little CLI tool that generates passwords for you. <a href=&#...阅读全文
Go语言 命令行解析(一)
命令行启动服务的方式,在后端使用非常广泛,如果有写过C语言的同学相信不难理解这一点!在C语言中,我们可以根据argc和argv来获取和解析命令行的参数,从而通过不同的参数调取不同的方法,同时也可以用Usage来打印帮助信息了。 那么开始今天的话题之前,我们回顾一下在C语言中是如何解析传递的参数的。 示例代码: #include
New to Go, need help with my first attempt.
<p>Hello,</p> <p>i'm fairly new to Go and i wanna mainly use to for web-development. Coming from PHP and being used to frameworks doing everything for me, this seems to be quite a challenge :P. I decided to start building tools that i'd need in order to not go mental, one of those tools would be a small "O...阅读全文
Docker Swarm代码分析笔记(17)——event_monitor.go
Engine结构体有一个eventsMonitor成员: type Engine struct { ...... eventsMonitor *EventsMonitor } EventsMonitor结构体定义如下: //EventsMonitor monitors events type EventsMonitor struct { stopChan chan struct{} cli client.APIClient handler func(msg events.Message) error } stopChan用来通知停止接受消息;cli是底层连接的client,而handler则是收到event的处理函数。 Engine.ConnectWithClient方法会给eventsMo...阅读全文
This is a longshot but does anybody happen to know what the Procfile should look like for a Caddy site on Heroku?
<p>There's a bunch of buildpacks but I can't find an example of a Procfile anywhere</p> <hr/>**评论:**<br/><br/>DenzelM: <pre><p>Are you having a specific problem? I don't have any experience with Caddy. But for Heroku you must <a href="https://devcenter.heroku.com/articles/depl...阅读全文
Go 每日一库之 gentleman
简介 gentleman是一个功能齐全、插件驱动的 HTTP 客户端。gentleman以扩展性为原则,可以基于内置的或第三方插件创建具有丰富特性的、可复用的 HTTP 客户端。相比标准库net/http,gentleman更灵活、易用。 快速使用 先安装: $ go get gopkg.in/h2non/gentleman.v2 复制代码后使用: package main import ( "fmt" "gopkg.in/h2non/gentleman.v2" ) func main() { cli := gentleman.New() cli.URL("https://dog.ceo") req := cli.Request() req.Path("/api/breeds/image/r...阅读全文
First Go project, looking for some feedback
<p><a href="https://github.com/mrnickel/StaticSiteGenerator">https://github.com/mrnickel/StaticSiteGenerator</a></p> <p>I've published a V0.1 of my first go project. It's another StaticSiteGenerator (yay!). Really wrote it in order to get my feet wet with something that I'm hoping to ac...阅读全文
Do you use multiple directories in GOPATH? Why?
<p>According to <code>go help gopath</code>, "The GOPATH environment variable lists places to look for Go code." In other words, you can specify multiple directories, not just <code>~/go</code> for example. </p> <p>I've only ever used one directory and don't really understan...阅读全文
Linux搭建Hyperledger Fabric v1.1.0
安装依赖 sudo apt-get update sudo apt-get install apt-transport-https ca-certificates curl software-properties-common git make gcc 使用国内的阿里源安装docker 当然也可以使用别的源,因为我的是阿里服务器,所以就选国内源了,其它源百度都有的。 curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/u...阅读全文
在Ubuntu上部署Fabric环境(+出错记录)
首先在VMware Workstation虚拟机上安装Ubuntu,配置好环境,调好中文语言、分辨率后,打开终端。 PS:在安装Ubuntu系统后如果发现与Windows系统的文件不能相互复制,网上查了很多教程,发现都是不能用的,能实现的方法如下所示: 打开终端,输入: sudo apt-get autoremove open-vm-tools sudo apt-get install open-vm-tools-desktop 然后重启 特别推荐 如果用户切换到root下,就不用考虑权限的问题,这样会省去哼多麻烦,不用加sudo,安装其他的软件业方便 cc@cc-fibric:~$ sudo -i [sudo] password for cc: root@cc-fibric:~# 接下来,...阅读全文
[Show] file_finder - First Go project. Would love feedback.
<h4><a href="https://github.com/cwramsey/file_finder">file_finder</a></h4> <p>I just finished writing a (very) short tool in Go to help get some of the basics in the language.</p> <p>It's a simple cli tool that (can recursively) find files matching a string.</p> <p>It'...阅读全文
[Geth源码]好用到失眠的命令行应用框架cli
Tag: 以太坊源码 Geth cli Go Golang command line source code 近期开始看以太坊源码,然后发现了这个神奇的,好用到失眠的命令行应用框架cli,因此推荐给大家。 Geth源码 Geth源码地址是 https://github.com/ethereum/go-ethereum.git,下载编译后,产出的geth等位于build/bin下 下载 mkdir -p $GOPATH/src/github.com/ethereum/ cd $GOPATH/src/github.com/ethereum/ git clone https://github.com/ethereum/go-ethereum.git 或者 go get github.com/eth...阅读全文
Go CLI Patterns
<p>Hey guys, </p> <p>looking for some patterns / examples of Go CLI tools. what are the best ways to implement it </p> <p>thanks!</p> <hr/>**评论:**<br/><br/>lktslionel: <pre><p>Cobra (<a href="https://github.com/spf13/cobra">https://github.com/spf13/cobra</a>) i...阅读全文
Hyperledger fabric环境搭建
title: Hyperledger fabric环境搭建 tags: Hyperledger, fabric 一、需要的环境 注意:本文是在CentOS下演示 1.安装golang 下载golang git clone https://studygolang.com/dl/golang/go1.11.linux-amd64.tar.gz 解压文件至 /usr/local目录。 tar -C /usr/local -xzf go1.11.linux-amd64.tar.gz 配置环境变量 打开 vim /etc/profile 添加下面的内容 export GOROOT=/usr/local/go export GOPATH=$HOME/go export PATH=$PATH:$GOROO...阅读全文
golang etcd简明教程
etcd 是一个高可用强一致性的键值仓库在很多分布式系统架构中得到了广泛的应用,本教程结合一些简单的例子介绍golang版本的etcd/clientv3中提供的主要功能及其使用方法。 如果还不熟悉etcd推荐先阅读: 看图轻松了解etcd etcd常用操作介绍 Let's get started now! 安装package 我们使用v3版本的etcd client, 首先通过go get下载并编译安装etcd clinet v3。 go get github.com/coreos/etcd/clientv3 该命令会将包下载到$GOPATH/src/github.com/coreos/etcd/clientv3中,所有相关依赖包会自动下载编译,包括protobuf、grpc等。 官方文档地...阅读全文
星云链源码分析一
星云链开始函数在cmd/neb/main.go 下main函数下使用github.com/urfave/cli进行命令行解析app := cli.NewApp()app.Action = nebapp.Name ="neb"app.Run(os.Args)具体可以去看这个包怎么使用往下进入neb函数func neb(ctx *cli.Context) error {n, err := makeNeb(ctx)select {case <-runNeb(ctx, n):return nil}这里只贴出主要函数有两个主要函数makeNeb和runNeb先从makeNeb进去看一看func makeNeb(ctx *cli.Context) (*neblet.Neblet, error){这函数返...阅读全文
Looking for feedback on CLI Movie Information Tool
<p>Hi! I made a really simple little utility to query OMDB for movie information yesterday, and was looking for feedback. Specifically on the code itself, how idiomatic it is and things of that nature. I've been writing Go for a while now, but know I still have a ways to go :) </p> <p><a href="https://github.com/aa...阅读全文
Best Golang cli apps
<p>Looking for inspiration. ;) Could you give me some examples of nice command line tools written with Go? </p> <p>Thanks! </p> <hr/>**评论:**<br/><br/>nemith: <pre><p>The 'go' tool itself is a good place to start. It is what inspires libraries like cobra.</p></pre>if...阅读全文
N26 Bank CLI
<p>Hi! I have written a small app to interact with N26 Bank API here on Germany. Code is at <a href="https://github.com/guitmz/n26-cli">https://github.com/guitmz/n26-cli</a></p> <hr/>**评论:**<br/><br/>dev_ire: <pre><p>It can be installed locally, i'm sure it can but what are the s...阅读全文
A small appreciation for testing in Go
<p>I really like that tests are typically in the same folder as the production code they test. It's a small thing, but a recent venture back into Ruby made me appreciate it.</p> <hr/>**评论:**<br/><br/>etherealflaim: <pre><p>I'm a big fan of the whole of Go testing. The simple minimalistic t...阅读全文
How to integration test the DAO layer in Go?
<p>Are there any recommendations on how to integration test the DAO layer in a Go program? I've seen lots of ways to test the code that depends on the DAO layer - using Interfaces being the prime one - but nothing about testing the DAO layer itself.</p> <p>Of particular concern is doing it in a way that works in a CI syst...阅读全文
Code review wanted! github.com/narqo/go-badge - A small library for rendering shield badges to SVG
<p><em>What I found most frustrating during my slow way to Go language is the lack of any sort of code review. And what I've leaned from my programming experiense is that reading and understanding other's (good) code is not the same as writing your own (good) code.</em> :)</p> <p>As a small study proje...阅读全文
Prevent go app exiting on panic
<p>I get that Go really really really really doesn't want you to use panics unless something truly is horribly horribly wrong. However, in the case of a web app, if something does panic, then my whole app exits and bam, no more web server. This freaks me the hell out. Is there any way to prevent this behavior within the app (other ...阅读全文
Docker Swarm代码分析笔记(15)——scheduler
Docker Swarm manage命令的scheduler是通过filter和strategy构建的(cli/manage.go): sched := scheduler.New(s, fs) 而scheduler实际的功能就是选择符合cluster.ContainerConfig要求的node(Docker Engine)列表: // SelectNodesForContainer will return a list of nodes where the container can // be scheduled, sorted by order or preference. func (s *Scheduler) SelectNodesForContainer(nodes []*n...阅读全文
Docker Swarm代码分析笔记(13)——filter
Docker Swarm manage命令的filter选项用来指定scheduler选择Docker Engine的过滤项,其变量定义如下(cli/flags.go): // hack for go vet flFilterValue = cli.StringSlice(filter.List()) // DefaultFilterNumber is exported DefaultFilterNumber = len(flFilterValue) flFilter = cli.StringSliceFlag{ Name: "filter, f", Usage: "filter to use [" + strings.Join(filter.List(), ", ") + "]", Val...阅读全文
CribbNotes CUI v1.0
<p>Hi, everyone. I would like to announce the first release of CribbNotes CUI (<a href="https://github.com/jameycribbs/cribbnotes_cui" rel="nofollow">https://github.com/jameycribbs/cribbnotes_cui</a>). CribbNotes CUI is a simple, console-user-interface note taking application written in Go and using the awesome g...阅读全文
Drone using sql.Open multiple times, it's OK?
<p>I know you should open the SQL connection once because it handles pooling for you, as talked about in this <a href="https://stackoverflow.com/questions/33578876/how-frequently-should-i-be-calling-sql-open-in-my-program">stackoverflow</a>.</p> <p>I was reading the Drone code and came across how they handle s...阅读全文
php cli执行过程
  --初识
etcd 是一个 golang 编写的分布式、高可用的一致性键值存储系统,是目前容器编排领域火热的 Kubernetes(k8s) 内置的服务发现与节点一致性中间件,用于提供可靠的分布式键值(key-value)存储、配置共享和服务发现等功能。etcd 可以用于存储关键数据和实现分布式调度,在现代化的集群运行中能够起到关键性的作用。 etcd 基于 Raft 协议,通过复制日志文件的方式来保证数据的强一致性。在 etcd 之前,常用的是基于 Paxos 协议的 ZooKeeper。 etcd etcd 主要特性有: 简单:基于 HTTP+JSON 的 API 让你用 curl 就可以轻松使用。 安全:可选 SSL 客户认证机制。 快速:每个实例每秒支持一千次写操作。 可信:使用 Raft 算...阅读全文
How to create an array that can contain items of 2 different types, but only those 2 types?
<p>For example, if I were to try and write this in Scala, I could do something like this:</p> <pre><code>sealed trait InputParameter case class InputArgument(value: String) extends InputParameter case class InputOption(name: String, value: Option[String]) extends InputParameter val params: List[InputParameter] = List( In...阅读全文
Docker Swarm代码分析笔记(3)——swarm create
Docker Swarm的create命令代码很简单: func create(c *cli.Context) { if len(c.Args()) != 0 { log.Fatalf("the `create` command takes no arguments. See '%s create --help'.", c.App.Name) } discovery := &token.Discovery{} discovery.Initialize("", 0, 0, nil) token, err := discovery.CreateCluster() if err != nil { log.Fatal(err) } fmt.Println(token) } 而token.Create...阅读全文
兄弟连区块链入门教程以太坊源码分析geth启动流程分析
区块链入门教程以太坊源码分析geth启动流程分析,2018年下半年,区块链行业正逐渐褪去发展之初的浮躁、回归理性,表面上看相关人才需求与身价似乎正在回落。但事实上,正是初期泡沫的渐退,让人们更多的关注点放在了区块链真正的技术之上。geth是我们的go-ethereum最主要的一个命令行工具。 也是我们的各种网络的接入点(主网络main-net 测试网络test-net 和私有网络)。支持运行在全节点模式或者轻量级节点模式。 其他程序可以通过它暴露的JSON RPC调用来访问以太坊网络的功能。如果什么命令都不输入直接运行geth。 就会默认启动一个全节点模式的节点。 连接到主网络。 我们看看启动的主要流程是什么,涉及到了那些组件。启动的main函数 cmd/geth/main.go看到main...阅读全文
golang cli 应用
## golang cli 应用封装 命令行应用,基本调用封装、参数获取 ~~~~gotemplate go get github.com/ctfang/command ~~~~ ### 基础使用 代码在 go get github.com/ctfang/command/examples/main.go ~~~~go package main import ( "github.com/ctfang/command" "log" ) func main() { app := command.New() app.AddCommand(Echo{}) app.AddCommand(Hello{}) app.Run() } // Echo 需要实现接口 CommandInterface type E...阅读全文
elasticsearch学习笔记-常用方法使用
go中elasticsearch sdk 常用基础操作1、创建客户端func getCli() *es.Client{cli :=es.SetURL("http://127.0.0.1:9200")client, err :=es.NewClient(es.SetSniff(enabled), cli)if err !=nil {panic(err)}}2、定义数据结构type ParamModel struct {Id int64 `json:"id"`Content string `son:"content"`.....}3、数据解析器func ParserFlOrder(res *es.SearchResult) (out interface{}) {temp :=ParamModel...阅读全文