Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not run example #62

Open
lucasjinreal opened this issue Jan 22, 2021 · 8 comments
Open

can not run example #62

lucasjinreal opened this issue Jan 22, 2021 · 8 comments
Labels
question Further information is requested

Comments

@lucasjinreal
Copy link

./main.go:15:7: undefined: workwx.RxMessageHandler
./main.go:18:53: undefined: workwx.RxMessage
./main.go:31:13: undefined: workwx.NewHTTPHandler
@xen0n
Copy link
Owner

xen0n commented Jan 22, 2021

Insufficient information, please provide more context (for example whole terminal session recorded with asciinema or similar services) so people could debug.

@xen0n xen0n added the question Further information is requested label Jan 22, 2021
@lucasjinreal
Copy link
Author

@xen0n Sure. I simply copied the example go code and created a simple project:

package main

import (
	"flag"
	"fmt"
	"net/http"

	"github.com/xen0n/go-workwx"
)

type dummyRxMessageHandler struct{}

var _ workwx.RxMessageHandler = dummyRxMessageHandler{}

// OnIncomingMessage 一条消息到来时的回调。
func (dummyRxMessageHandler) OnIncomingMessage(msg *workwx.RxMessage) error {
	// You can do much more!
	fmt.Printf("incoming message: %s\n", msg)
	return nil
}

func main() {
	pAddr := flag.String("addr", "[::]:8000", "address and port to listen on")
	pToken := flag.String("token", "", "configured Token of your work weixin app")
	pEncodingAESKey := flag.String("key", "", "configured EncodingAESKey of your work weixin app")

	flag.Parse()

	hh, err := workwx.NewHTTPHandler(*pToken, *pEncodingAESKey, dummyRxMessageHandler{})
	if err != nil {
		panic(err)
	}

	mux := http.NewServeMux()
	mux.Handle("/", hh)

	err = http.ListenAndServe(*pAddr, mux)
	if err != nil {
		panic(err)
	}
}

When i run go build -o main *.go, the error when build:


Oh, I using another machine and not using go.mod, it seems can build

@lucasjinreal
Copy link
Author

@xen0n How to get this 2 params?

	pToken := flag.String("token", "", "configured Token of your work weixin app")
	pEncodingAESKey := flag.String("key", "", "configured EncodingAESKey of your work weixin app")

@xen0n
Copy link
Owner

xen0n commented Jan 22, 2021

Oh, I using another machine and not using go.mod, it seems can build

Simply ensure your environment is clean then. ;-)

How to get this 2 params?

You just follow the official docs step by step. The Token and EncodingAESKey nomenclature is deliberately kept consistent.

@lucasjinreal
Copy link
Author

@xen0n Which official step? I can not found such field in Wechatwork's doc.

@xen0n
Copy link
Owner

xen0n commented Jan 23, 2021

@xen0n Which official step? I can not found such field in Wechatwork's doc.

Try this

@lucasjinreal
Copy link
Author

@xen0n thanks!

How's the url in the settings? I only need to set token and encodedAESKey ?

@xen0n
Copy link
Owner

xen0n commented Jan 24, 2021

@xen0n thanks!

How's the url in the settings? I only need to set token and encodedAESKey ?

You have to mount the application at some domain, of course. Once you have the receiver properly exposed, simply fill in the two parameters and the test for receiving messages should just succeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants