Skip to content

Add Go/golang example code #399

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

Merged
merged 3 commits into from
May 27, 2025

Conversation

KEINOS
Copy link
Contributor

@KEINOS KEINOS commented Mar 26, 2025

♻️ Current situation

  • There is no Go (golang) example in the README.md 😢
  • Swift example code is missing the link in the index of README.md

Testing

  • Tested on:
    • go version go1.24.1 darwin/amd64
    • go version go1.24.1 linux/amd64 | golang:alpine @ Docker
  • This code should work in Go v17+.

Reviewer Nudging

Local run

If Go (golang, v1.17+) is installed locally:

  1. Create a main.go file in the working directory
  2. Copy & paste the example code of Go to main.go
  3. Replace the token and secret variable in the main.go
  4. Initialize the modules and build/run the code:
$ go mod init example/switchbot && go mod tidy
**snip**

$ go run main.go
**snip**

Docker run

Using docker may be useful if Go/golang is not installed locally:

  1. Create a main.go file in the working directory
  2. Copy & paste the example code of Go to main.go
  3. Replace the token and secret variable in the main.go
  4. Pull the latest Go image of Docker
    $ docker pull golang:alpine
  5. Mount the source code and instantiate a container and run:
    $ docker run --rm -it -v "$(pwd)":/app -w /app golang:alpine /bin/sh
    /app # go mod init example/switchbot && go mod tidy
    **snip**
    
    /app # go run main.go
    **snip**
    

@KEINOS KEINOS force-pushed the add-example-golang branch from 6d8967b to d68def7 Compare May 3, 2025 12:29
@donavanbecker donavanbecker merged commit cd5c350 into OpenWonderLabs:main May 27, 2025
@KEINOS KEINOS deleted the add-example-golang branch May 28, 2025 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants