如何全局定义结构并重用其包

Im very new to Go and have this "design" problem.

I have a main program passing jobs through channels. Each job will end up in a function defined in separate "worker" packages. Jobs are structs.

Now i want each function called, to return result as a common struct through a "result" channel. But the package doesnt know about the struct definition i have in main and so i cannot define it.

package main

type resultEvent struct {
    name  string
    desc  string
}

Then in a worker package:

package worker

func Test() {
   result := &resultEvent{name: "test"}
}    

Of course the idea is to eventually send this result down a channel, but even this simple example wont work, because worker doesnt know about resultEvent. What would be the correct way of doing this?

Update:

It should be noted that there will be many worker packages, doing different things. Sorta like "plugins" (only not pluggable at all). I dont want to define a redundant struct in each go-file and then have to maintain that over maybe 50 very different worker-packages.

Im looking for what would be the correct way to structure this, so i can reuse one struct for all worker-packages.

One possible way would be something like:

package workerlib

type ResultEvent struct {
  Name        string  // Export the struct fields, unless you have a
  Description string  // real good reason not to.
}

Then stick the rest of the worker utility functions in that package. Unless you provide suitable methods to read the name and description from an event, simply export the fields. If you have an absolute need to make them changeable only from within the package they're defined in, you could keep them unexported, then provide a function to create a ResultEvent as well as methods to read the name and description.

No matter what, you will have to import the package which contains the type you'd like to use. However, the reason this isn't working for you is because your type is not exported. You need to uppercase the types name like;

type ResultEvent struct {
    name  string
    desc  string
}

Worth checking out what exported vs unexported means but basically upper case means exported which is similar to the public specifier in other systems languages. Lower case means unexported which is more like internal or private.

As pointed out in the comment and other answer you can't import main so I believe you'll have to move your types definition as well.

Basically, anything that lives in package main will only ever be able to be referenced from that pacakge. If you want it to be shared between multiple packages, put it in the worker package and export it (Upper case the first letter), then import worker from main.