./pkg.go:5: imported and not used: "v.io/x/lib/ibe"
This means the code in pkg.go
does not use the package. In this case the next error indicates where you mean to.
./pkg.go:19: undefined: SetupBB1
The means the compiler did not find SetupBB1
. I found SetupBB1
in the ibe
package. The compiler did not find it because things from other packages need to be prefixed with the package name, in this case ibe.SetupBB1()
.
./pkg.go:20: no new variables on left side of :=
:=
defines and sets the variables on its left hand side. It won’t redefine variables in the same scope (but will shadow variables from scopes higher in the stack). The line in question is:
pk, err := master.Extract(stringToBin(Macid))
pk
was declared in the function signature: func ExtractPK(id string) (pk string)
.
err
was declared on the previous line.
After fixing these errors, the next one encountered is:
./pkg.go:20: cannot assign ibe.PrivateKey to pk (type string) in multiple assignment
This happens because pk
was declared as a string in the function signature, but the first value returned from from master.Extract
is an ibe.PrivateKey
.
How to continue depends on what you intend the program to do. As it stands, the program expects to combine the results of ExtractPK
with a string, which means the result of ExtractPK must be a string. I don’t see a reason other than debugging to do this. If you really need to, use ibe.MarshalPrivateKey
and convert the resulting []byte
to a string.
None of the errors in this program are handled. Errors tell you when things aren’t working, and frequently can be used to figure out why and how to fix it. My preferred method is https://pocketgophers.com/error-checking-while-prototyping/ because it requires minimal thinking (allowing you to focus on the program and not the errors) and tells you the filename and line number where the error was handled.