You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert
今まで golang で変数名や関数名のリネームには gofmt の -r オプションを使ってきましたが、これからは gorename を使いましょう。 文法を解析して正しくリネームしてくれるので、gofmt で起き得た誤爆も心配ありません。インストールは以下の様に実行します。 $ go get golang.org/x/tools/cmd/gorename 使用方法は以下の通り。 gorename: precise type-safe renaming of identifiers in Go source code. Usage: gorename (-from <spec> | -offset <file>:#<byte-offset>) -to <name> [-force] You must specify the object (named entity) to rename
Rob Pike 12 January 2015 A common point of discussion among Go programmers, especially those new to the language, is how to handle errors. The conversation often turns into a lament at the number of times the sequence if err != nil { return err } shows up. We recently scanned all the open source projects we could find and discovered that this snippet occurs only once per page or two, less often th
In this hacking session, Andrew Gerrand and Brad Fitzpatrick write the new version of tip.golang.org, a site that serves leading-edge documentation for the Go core. Source → https://goo.gle/3Od2yby Hacking with Andrew and Brad Playlist → https://goo.gle/3M57ZqX Subscribe to The Go Channel → https://goo.gle/go-subscribe #GoLang #HackingWithAndrewAndBrad
package main import ( "fmt" "log" "net/http" ) func baseHandlerFunc(handler func(w http.ResponseWriter, r *http.Request)) http.Handler { return baseHandler(http.HandlerFunc(handler)) } func baseHandler(handler http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // common log.Println(r.URL, r.Method) handler.ServeHTTP(w, r) }) } // handler func index(
あけおめ〜。Go 界においてジェネリクスを求めるのは(今のところ)はかない望みでしかないし、もちろん重々承知していることですが、それでもときどき複雑なものを書こうとするとどうしても複数の型に対応する関数が欲しくなる。そこでこの冬休みになにかうまい方法はないかと考えて、作ってみました。 要件 今回はこんな関数が実現したくなりました。(擬似コードです) // map[string]int とか map[string]foo.Bar を受けつける func keys(m map[string]T) []string { keys := make([]string, 0, len(m)) for k := range m { keys = append(keys, k) } return keys } そしてこれを実現するためのアプローチを以下のように定めました。 reflect パッケージを使わ
If you want data persistence in your Go application, most likely you're thinking of using some database. The easiest and probably the most convenient for deployment are embedded databases. There are many wrappers for C databases, however Go developers usually prefer pure Golang solutions. Bolt is the way to go: it's a pure Go embedded key/value database, which is easy to use for persistence in you
はじめに Go 1.4 にて導入されたgo generateコマンドを使って、JSONファイルからソースコードを自動生成してみます。 今回は、JSONファイルに定義されたWebアプリケーションのルーティング情報をもとに、ルーターのプログラムが記載された単純なソースコードを生成してみます。 今回の手順で作成したソースコードは、こちらのリポジトリに格納しています。 今回、ルーターにはgorilla/muxを使用しています。 JSONファイルからソースコードを生成するコマンドの作成 まずは、以下のようなルーティング情報が記載されているJSONファイルを読み込み、ルーターのプログラムが記載されたソースコードを生成するコマンドを作成します。 [ {"method": "GET", "path": "/", "handler": "topHandler"}, {"method": "GET", "pa
Gates of Olympus: Judi Olympus Slot 1000 di Maha168 Gates of Olympus adalah salah satu game slot online populer dari Pragmatic Play yang menghadirkan pengalaman bermain bertema mitologi Yunani. Di dalam permainan ini, pemain akan berhadapan langsung dengan Zeus, dewa petir yang legendaris, lengkap dengan simbol khas seperti mahkota, cincin, dan petir. Berkat berbagai fitur menarik yang ditawarkan,
Go has seen many converts from scripting languages such as Ruby and Python. These newcomers love the type safety, the language simplicity, and the static binaries that Go offers. Unfortunately, these features are lost once developers dive into the built-in templating libraries: text/template & html/template. We’ll look at ego – a type safe templating language – that preserves all these features an
このブログは2年ほどOctopressを使って生成してきたが,不満が限界に達したので,Go言語で作られたHugoに移行した. Octopressへの不満は,とにかく生成が遅いこと.100記事を超えた辺から耐えられない遅さになり,最終的には約150記事の生成に40秒もかかっていた.ブログは頻繁に書くのでかなりストレスになっていた. Hugoのうりは生成速度.試しに使ったところ,明らかに速く,すぐに移行を決めた.最終的な生成時間は以下.爆速. 他に良いところを挙げると,まずとてもシンプル.Octopressと比べても圧倒的に必要なファイルは少ない.また,後発だけあって嬉しい機能もいくつかある.例えば,draftタグを記事のヘッダに書いておけば,ローカルでは生成されても,本番用の生成からは外されるなどなど. インストール Go言語で書かれているのでgo getして,デザインテーマをCloneする
Goで作られるプログラムサイズはそこそこ大きい。配布する場合はやはり小さい方が良い。 そんなときは、リンカの設定を利用するといいようだ。 1 go build -ldflags '-s -w' Linuxならバイナリサイズが小さくなるはずだ。拙作、comstockでは8MiBから5.2MiBに縮んだ。 何をやっているか? -ldflagsは、gccなどを使ったことある方はよくご存知だろうが、ldへの引数である。 ldとはgccが使うリンカであり、Goもリンカを持っている。Goのリンカは、例えば、go tool 6l(番号はアーキテクチャ依存)から呼び出せる。伝統的にリンカへのフラグは LDFLAGSであるので、goでは小文字で指定するようになってる。 go buildはリンカへの引数を-ldflagsの後で文字列として渡すことができる。 指定できるリンカフラグは様々で、標準ドキュメントより
Unfortunately, I haven’t been writing as much as I’d like to lately. Partially this is because I’ve been quite busy with Docker-related things, but it also has a lot to do with aspects of my blogging stack (and approach) that were beginning to show their weaknesses. The way that this blog got started was as an Octopress installation on a Macbook Air. I loved the Octopress default theme’s clean des
Published: Monday, December 01, 2014 Last modified: Monday, January 09, 2023 by Dominik Honnef Go is an amazing language, but not just because of its language features, but also because of its ecosystem and how easy it is to write tools that operate on Go code. While languages and frameworks like Java and .NET have popular IDEs (e.g. Eclipse and Visual Studio) that can do formatting, refactoring,
はじめに 先月の GoCon 2014 Autumn のキーノートスピーチで Rob Pike 先生が、「Simplicity is Complicated」というタイトルで講演を行いました( @tenntenn さんによるレポート記事 )。 その中で、「Go の定数は、裏では非常に複雑なことをやっている」という話をされていました。そのときに触れられていた、The Go blog の "Constants" という記事を読んだので、それについてまとめます。 TL;DR Go では、異なる型を混ぜた式は禁止し明示的な変換を要求する しかし、定数を毎回変換するのは面倒なので、定数は型を持たないことが可能になっている これによって、Go の定数は、実際の数字のように扱うことができる 参考文献 参考というか、そのままなので、下記を読めば、本記事を読む必要はありません。また、本記事を読んで興味を持っ
Deploying with “git push” the Docker Way Many people have asked me how we set up the GopherAcademy blog to automatically deploy when we push a commit. In this Go Advent 2014 article I’m going to walk through the process so you can see what is involved and decide if it’s right for your setup. Why Deployment can be the hardest part of any project. Docker certainly makes that step easier but the ecos
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く