LoginSignup
0
0

More than 1 year has passed since last update.

【Golang】mapに複数のキーを設定する

Posted at

個人的に感動的に便利だったので、書いておきます。

コード

mapのキーにstructを設定すると出来ます。
複数のキーで一つの値を持っておきたい時に便利です

package main

import (
    "fmt"
)

type key struct {
    key1 string
    key2 string
}

func main() {
    m := map[key]string{
        key{
            key1: "hoge_key1",
            key2: "hoge_key2",
        }: "hoge",
    }

    fmt.Println(m)
}
// 結果:map[{hoge_key1 hoge_key2}:hoge]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0