概要 去年の8月に社会人エンジニアになり、今年の2月までAPIサーバーの開発をRuby on Railsで行なっていた新卒Rubyistです。 3月にサーバーサイドを全てGolangで行う会社に転職しました。今までRailsでの業務が多かったため、interface{}という概念がどうしても身につきませんでしたが、ある程度業務に慣れ、戦い続けて学んだことをまとめようと思いました。 Golangのinterfaceについては知見は多くあるのですが、今年はアウトプットを大事にしていきたいという目標から、記事にまとめました。 下に読む前に Golangのインタフェースは型の1つです。 string や int64 が関数を持っているように、インタフェースで型を宣言してその型に関数を持たせることができます。 構造体がインタフェースで宣言されているGetRadius関数を持つと、この構造体の型はCi
golangでbyteをstringに変換する処理はたびたび発生するのですが、 手抜きで fmt.Sprintf("%s", byte) などとやっちゃうこともあるのでそれぞれの書き方でどれが速いのか確認してみた。 1) Sprintfを使うパターン fmt.Sprintf("%s", data) 2) string() を使うパターン string(data) 3) unsafe を使うパターン *(*string)(unsafe.Pointer(&data)) 唐突にテストコード package main import ( "fmt" "unsafe" "testing" ) var data = []byte("はろーhogehogeです。") func Benchmark_Sprintf(b *testing.B){ b.ResetTimer() for i := 0; i < b
var c complex128 = complex(1, 2) // 複素数に変換 var fr float64 = real(c) // 実数に戻す var fi float64 = imag(c) // 実数に戻す fmt.Println(fr, fi) //表示[1 2] 関数みたいに書くと ・実数→複素数 complex(real, imag float)complex ・複素数→実数 real(c complex)float imag(c complex)float といった感じです (float32,64はそれぞれcomplex64,128に対応します) 標準パッケージ https://golang.org/pkg/math/cmplx/ import "math/cmplx" これで標準パッケージが使えます。 mathパッケージにもあるような便利な関数が入っています。 cm
Rob Pike 7 July 2010 Introduction Newcomers to Go wonder why the declaration syntax is different from the tradition established in the C family. In this post we’ll compare the two approaches and explain why Go’s declarations look as they do. C syntax First, let’s talk about C syntax. C took an unusual and clever approach to declaration syntax. Instead of describing the types with special syntax, o
はじめに タイトルをキャッチーかつ若干煽り気味にしたのは、そもそも記事を見てもらう確率を上げるためで他意はありません。なぜ読んでほしいのかというと、typeとstructについて、一部の機能に着目して、それがtypeとstructの全てだと誤解されるとマズいなと感じることが最近多いためです。 この記事で書いてあることは過去にもインタフェースの実装パターンや2016年度Go研修で取り上げていますが、今回は端的に分かりやすくなるようにまとめたいと思います。
I’ll introduce how to represent sum/union/variant(-like) type in Go first. Then, I’ll introduce ‘gosumcheck’, which is a static lint tool which checks all possible cases of type-switch. This is a post for Hatena Engineer Advent Calendar 2016 (Japanese). Sum Type in GoSo, what is sum/union/variant type? From Wikipedia, In computer science, a tagged union, also called a variant, variant record, disc
Introduction This is the reference manual for the Go programming language. The pre-Go1.18 version, without generics, can be found here. For more information and other documents, see go.dev. Go is a general-purpose language designed with systems programming in mind. It is strongly typed and garbage-collected and has explicit support for concurrent programming. Programs are constructed from packages
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く