如何动态调用变量?

I have two variables:

somethingA := 123
somethingB := 456

This two variables are filled though the system and lets presume that you have third variable:

type := "A"

With third variable you want to call somethingA but not like following:

if type == "A" {
    return somethingA
}else{
    return somethingB
}

but something like:

return something{type}

Is something like this possible in go?

Thank you

Is something like this possible in go?

No.

All ways to do something like this boils down to the solution you showed.

use a map

package main

import (
    "fmt"
)

func main() {
        x:=make(map[string]int)
        x["SomethingA"]=123
        x["SomethingB"]=456
    fmt.Println(x["SomethingA"])
    fmt.Println(x["SomethingB"])
}