I want to access value(string) from key(int) which are mapped in a struct. Any leads. I have written a code in javaScript. I want to perform similar in go.
Here is the code in Javascript.
function resetCause(bits) {
var resetDictionary = {
'1': 'Watchdog Reset',
'2': 'Power On Reset',
'3': 'System Request Reset',
'4': 'Other Resets',
};
return resetDictionary[bits];
}
Here bits is a decimal value (basically 1,2,3,4)which I can pass from part of the code and access the value (string).
Yes, but how do i access the value when I pass the key.
E.g. I want to put the value (string) into a new variable by calling the function. In JavaScript
I have a problem in setting the gopath. Even after setting up the workspace as subpath within the the GOPATH. I’m not able to access the libraries. It throws me this error.
C:\Go\go-work>go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\userName\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Go\go-work
set GOPROXY=
set GORACE=
set GOROOT=c:\go
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\userName\AppData\Local\Temp\go-build137919522=/tmp/go-build -gno-record-gcc-switches
I would suggest you to put your code into C:\Go\go-work\src.
For example, if your project is someproject, then it should be in path C:\Go\go-work\src\someproject and then do you imports.
I checked that too corrected it. When I’m compiling (Atom) everything is fine now no errors. When executing the test commands for the code on commandLine the following error is thrown.
The system cannot find the file specified.
This is because i’m trying to import one of the libraries which I cannot execute without and the naming system of this library is poor.
My current path looks like this
C:\Go\go-work\src\gobps
considered this also. I guess this is how it looked after installation.