Giter VIP home page Giter VIP logo

mrooze-zeng / go-wasm-demo Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 14.55 MB

Go wasm 学习相关demo,主要功能包括:md5处理,图像旋转,excel和csv生成,图像缩略图,gzip压缩和解压,切片上传和切片下载

Home Page: https://mrooze-zeng.github.io/go-wasm-demo/

Go 97.67% Makefile 2.33%
webassembly md5-hash md5 excel-export excel csv csv-files image-processing gzip-compression gzipped-files file-upload file-slice file-slicer

go-wasm-demo's Introduction

go wasm demo 学习

预览地址

  // 文件md5
	js.Global().Set("getMd5", app.GetMD5())
	// 随机旋转图片
	js.Global().Set("imageRotate", make(map[string]interface{}))
	imageRotate := app.ImageRotate()
	js.Global().Get("imageRotate").Set("run", imageRotate["run"])
	js.Global().Get("imageRotate").Set("release", imageRotate["release"])
	// 生成excel测试文件
	js.Global().Set("getExcel", app.Excel())
	// 生成csv测试文件
	js.Global().Set("setCSV", app.Csv())
	// 生成图片缩略图
	js.Global().Set("getImageThumbnail", app.ImageThumbnail())
	// 处理视频文件
	js.Global().Set("parseVideo", app.ParseVideo())

	//gzip 解压
	compressGzip := app.CompressGzip()
	js.Global().Set("compress", make(map[string]interface{}))
	js.Global().Get("compress").Set("gzip", compressGzip["gzip"])
	js.Global().Get("compress").Set("ungzip", compressGzip["ungzip"])

	//切片上传
	js.Global().Set("sliceUpload", app.SliceUpload())

    //切片下载
	js.Global().Set("sliceDownload", app.SliceDownload())
  • 用 go md5 包在 web 前端生成文件或者字符的 MD5

  • 随机旋转图片

  • 生成 excel/csv 测试文件并下载

  • 生成图片缩略图

  • 压缩上传文件和解压上传文件

  • 前端文件切片上传

  • 前端文件切片下载

常用命令

普通打包

  make

tinygo 打包

  make build-tiny
  • 注:由于部分包不支持,打包会失败,只能用普通打包的方式

启动本地文件上传服务

  make serve

网页预览

  cd demo && npx serve -s .
  或者
  cd demo && php -S 127.0.0.1:5000
  • 需要安装 nodejs 或者 PHP

已知问题:

  • 在 Tinygo 中(用 go 不会出现内存大量占用的情况,且耗时比 tinygo 的更少,但打包后的文件很大)
	buffer := make([]byte, args[0].Get("length").Int())

大量的 buffer 会消耗大量时间,并堵塞其他程序运行(处理方法,将重复的文件缓存在变量中,减少重复占用内存)

  • 在 TinyGo 中,不支持 encoding/xml,生成 excel 不可用 TinyGo

go-wasm-demo's People

Contributors

mrooze-zeng avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

qzy123456

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.