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

Add support for Golang #95

Closed
Angelmmiguel opened this issue Feb 16, 2023 · 4 comments · Fixed by #129
Closed

Add support for Golang #95

Angelmmiguel opened this issue Feb 16, 2023 · 4 comments · Fixed by #129
Assignees
Labels
🚀 enhancement New feature or request

Comments

@Angelmmiguel
Copy link
Contributor

Angelmmiguel commented Feb 16, 2023

Golang is a popular programming language. Currently, you can compile Go apps to Wasm + WASI using TinyGo. The Go team will release a formal support for Wasm + WASI (preview1) in 1.21 (August 2023).

Golang can be compiled to WebAssembly, so there's no requirement of a language runtime like Python, Ruby or JavaScript. The goal for this task is to create the wrapper code to interact with Wasm Workers Server. The same approach we took for the Rust support.

Technical requirements

These are the for the Golang support:

  1. Read the JSON metadata that comes via STDIN. Here you have the example from the Rust kit:

    pub struct Input {
    url: String,
    method: String,
    headers: HashMap<String, String>,
    body: String,
    kv: HashMap<String, String>,
    #[serde(default)]
    params: HashMap<String, String>,
    }

  2. Define the Request, Response and Cache entities. If it's available, it's better to use primitives from the Golang standard library or common usage libraries.

  3. Initialize a Request object from the JSON metadata.

  4. Initialize the Cache store.

  5. Call the worker function with the Request instance.

  6. Detect the content in the response. If it's a valid UTF-8 string, we can return. If it uses a different encoding, you need to encode it in base64.

  7. Transform the response and the Cache status into the expected JSON output. Note that the base64 flag is only enabled when the content is encoded.

    pub struct Output {
    data: String,
    headers: HashMap<String, String>,
    status: u16,
    kv: HashMap<String, String>,
    base64: bool,
    }

  8. Print the JSON output via STDOUT

Additional notes

  • The library should be defined in the kits/go folder.
  • The documentation is available in the site: https://workers.wasmlabs.dev/docs/languages/introduction.
  • Currently, we're not publishing the libraries to language registries. Instead, we document how to get it from the GitHub repository.
@Angelmmiguel Angelmmiguel added the 🚀 enhancement New feature or request label Feb 16, 2023
@mnafees
Copy link
Contributor

mnafees commented May 15, 2023

Hey @Angelmmiguel, I would like to take this up.

@Angelmmiguel
Copy link
Contributor Author

Angelmmiguel commented May 15, 2023

That's amazing @mnafees! I assigned the task to you to keep track of it. I also updated the task to provide a better description of the requirements to complete it.

Please, feel free to ask any question and open a draft PR in case you want to share some early code for feedback. And thank you for your interest on contributing! 😄

@mnafees
Copy link
Contributor

mnafees commented May 16, 2023

Hi @Angelmmiguel, opened a basic draft PR. I will be updating the PR with examples in a following commit!

@Angelmmiguel
Copy link
Contributor Author

Hi @Angelmmiguel, opened a basic draft PR. I will be updating the PR with examples in a following commit!

That's amazing! I already enabled the CI on the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants