Go(lang) Help

Status
This thread has been locked.

Elina

Ellie
Premium
Feedback score
3
Posts
32
Reactions
11
Resources
0
Hi, so I recently started learning Go but having some issues with the confusing (For me) variable system. Looked at all wikis and all.

So I have a variable in a package called "lib" (yes the variable is exported) and I want to access this in another package called "handler" but its not importing there? Really wierd.

I doubt I'll get many replies due to the language but worth a shot.

Thanks
Ellie
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Elina

Ellie
Premium
Feedback score
3
Posts
32
Reactions
11
Resources
0
Can you post the current code?
Sure..

This in `libs/errors.go` (the error descriptions are very vague on purpose)
Code:
var InvalidRequest = encode(errorData{"InvalidMethod", "Invalid method verb"}) // encode returns a string + errorData is a struct
var BadAuth = encode(errorData{"BadAuthentication", "Bad authentication code"})
var BadTarget = encode(errorData{"BadTarget", "No or invalid target specified"})
var BadPayload = encode(errorData{"BadPayload", "Bad payload sent"})

This can be accessed with ease through main.go in root.

Then in `handler/uhchandle.go`

Code:
func handleUHCRequest(req *http.Request) (string, int) {
    data := req.FormValue("data")

    var reqData uhcRequest

    err := json.Unmarshal([]byte(data), reqData)

    if err != nil {
        return BadPayload, 400 // <--- error here with imports.
    }

    return "test", 1
}

In `handlers/uhchandle.go`'s imports. When I add
Code:
"../main"
Visual Studio removes it
 
Last edited:
Status
This thread has been locked.
Top