Go WebAssembly Tutorial - Building a Calculator

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ม.ค. 2025

ความคิดเห็น • 55

  • @Tutorialedge
    @Tutorialedge  6 ปีที่แล้ว +7

    The Source Code for this entire project can be found here: github.com/TutorialEdge/Go/tree/master/go-webassembly-tutorial

    • @sntshkmr60
      @sntshkmr60 5 ปีที่แล้ว +7

      Dead link.

    • @shakerlakes
      @shakerlakes 4 ปีที่แล้ว

      Broken link. The correct one seems to be: github.com/elliotforbes/go-webassembly-framework

  • @josephkeller2521
    @josephkeller2521 4 ปีที่แล้ว +9

    Depending on your version of Go, you might have to do some fiddling with the 'server.go' file in order to run this and export the lib.wasm properly. For me, I had to change the main function in 'server.go' to another function name, ("runserver()"), for instance. Then, you'll need to call 'runServer()' in the main.go file, under the main function.
    Finally, when compiling the lib.wasm, file you'll need to run ALL of the go files in that directory. You're command line should look like this:
    GOARCH=wasm GOOS=js go build -o lib.wasm *.go
    Let me know if that works for you all!

  • @mahansathees
    @mahansathees 5 ปีที่แล้ว +3

    Hi Elliot
    Can you kindly update the flowing function according to go version 1.12.3? because js.NewCallback() had been drop. I couldn’t work around
    .
    func registerCallbacks() {

    js.Global().Set("add", js.NewCallback(add))
    js.Global().Set("subtract", js.NewCallback(subtract))
    }
    thanks

  • @jlhl6487
    @jlhl6487 5 ปีที่แล้ว +6

    the example don't run on go 1.12 ,because 1.12 have delete "js.NewCallback" API, and instead of Funccof

    • @emilywilliams6403
      @emilywilliams6403 5 ปีที่แล้ว

      even when I change to funcOf i'm getting some weird errors :/

    • @En0xer
      @En0xer 4 ปีที่แล้ว +1

      ​@@emilywilliams6403 Change the signature of the function you want to register using FuncOf
      1. Add a parameter of type js.Value
      2. The function must return an empty interface (I think this will change in the future)
      From: func add(i []js.Value) { ...... }
      To: func add(this js.Value, i []js.Value) interface{} { ...... return 'something'}
      Hope it helps!

  • @hi_arav
    @hi_arav 6 ปีที่แล้ว +2

    Congrats on the Awesome Go shoutout!

  • @Andrew-uk4oo
    @Andrew-uk4oo 6 ปีที่แล้ว +2

    What theme with arrows in terminal is used?

    • @bquinn1992
      @bquinn1992 6 ปีที่แล้ว

      Oh my zsh default theme, 'robbyrussell'

  • @GifCoDigital
    @GifCoDigital 6 ปีที่แล้ว +1

    So stupid questions.... the actual function calls are running on the client right? Not the server?

    • @Tutorialedge
      @Tutorialedge  6 ปีที่แล้ว +1

      It's not a stupid question at all, these functions are indeed executed within the client and not the server.

    • @GifCoDigital
      @GifCoDigital 6 ปีที่แล้ว +1

      Thanks! Im just getting started with Go, what would be a more practical use case for this where plain old JS wouldnt cut it? Would it mainly be multi threaded tasks?

    • @पापानटोले
      @पापानटोले 5 ปีที่แล้ว +1

      @@GifCoDigital
      Use cases are very very limited. If you want nano-second performance like some 3D games or some image editing application. etc Not for 99% of web apps i guess.

  • @dr.briaro
    @dr.briaro 2 ปีที่แล้ว

    I cant fint the split temp terminal.

  • @vencelam8287
    @vencelam8287 6 ปีที่แล้ว +1

    I'd like to know the purpose of this line:
    js.Global().Set("output", ...);
    What is it doing? You have another println() called under it to output the result.

    • @gtclaan
      @gtclaan 5 ปีที่แล้ว +1

      I agree, the js.Global().Set("output", ...) line is useless. What this line does is it sets the value of the Javascript variable 'output'. But he doesn't use the 'output' variable anywhere in this tutorial, so its only confusing.
      I liked the rest of the tutorial though. Thanks for making it.

    • @emilywilliams6403
      @emilywilliams6403 5 ปีที่แล้ว

      glad I'm not the only one going crazy at this part. I'm getting lots of errors too I think more than one thing might be outdated.

  • @zedwong2486
    @zedwong2486 3 ปีที่แล้ว

    Thank you so much!

  • @davidle5711
    @davidle5711 4 ปีที่แล้ว +1

    Can this run on windows 10 home ? I feel there are many errors

  • @MenkoDany
    @MenkoDany 6 ปีที่แล้ว

    Is this hosted anywhere so that I can test it before I try the tutorial? Or any other wasm example written in go?

    • @Tutorialedge
      @Tutorialedge  6 ปีที่แล้ว +1

      Here's the repo for this particular tutorial - github.com/TutorialEdge/Go/tree/master/go-webassembly-tutorial

    • @dz_s
      @dz_s 6 ปีที่แล้ว

      @@Tutorialedge would be great if you pin it. Thx

    • @MenkoDany
      @MenkoDany 6 ปีที่แล้ว

      I found the repo, I was asking if I could try it in the browser first

  • @carloslfu
    @carloslfu 5 ปีที่แล้ว

    Great, thanks!

  • @ATOM1671976
    @ATOM1671976 4 ปีที่แล้ว

    Nice!

  • @maniturox8700
    @maniturox8700 4 ปีที่แล้ว +1

    i need help regarding .WASM file??

  • @dead4youlots
    @dead4youlots 6 ปีที่แล้ว

    What ide/texteditor is this?

  •  6 ปีที่แล้ว

    correct link : tutorialedge.net/golang/go-webassembly-tutorial/

    • @Tutorialedge
      @Tutorialedge  6 ปีที่แล้ว +1

      Good catch! I've updated the link :) Thanks for your help!

  • @tommyye5140
    @tommyye5140 6 ปีที่แล้ว

    I checked the js dir there. But the build cmd always printed error.
    main.go:5:2: build constraints exclude all Go files in D:\software\GO\src\syscall\js

    • @Tutorialedge
      @Tutorialedge  6 ปีที่แล้ว

      This was something that I too encountered when upgrading to Go v1.11. Ensure your GOPATH and GOROOT are both pointed to your new Go 1.11 installation and that when you are performing the build, it is using the appropriate GOARCH and GOOS settings. Give this a shot and let me know how you get on :)

  • @touristtam
    @touristtam 6 ปีที่แล้ว +1

    Would you see this in prod as opposed to having an API written in Go and a (what ever flavour of the month) JS client ?

    • @Tutorialedge
      @Tutorialedge  6 ปีที่แล้ว +1

      It's still an experimental port for now, but when it becomes more mature I can definitely envision new frameworks coming out that are built purely in Go.
      I can see these simplifiying the way we do things within our web apps and providing us a lot more flexibility and freedom.

    • @MakisMaropoulos
      @MakisMaropoulos 6 ปีที่แล้ว +1

      Iris web framework has already an example on its repository for webassemply + javascript + iris backend API, you may want to take a look at github.com/kataras/iris/tree/master/_examples

  • @serdcemsvami
    @serdcemsvami 5 ปีที่แล้ว +1

    Goolobal 😀

  • @dz_s
    @dz_s 6 ปีที่แล้ว

    Could you provide source code please? Thx.

    • @Tutorialedge
      @Tutorialedge  6 ปีที่แล้ว +1

      github.com/TutorialEdge/Go/tree/master/go-webassembly-tutorial - here you go! :D

    • @पापानटोले
      @पापानटोले 5 ปีที่แล้ว

      @@Tutorialedge
      Thats not working.
      also Go 1.12 nothing works. I think still way ahead.

  • @khaioan2766
    @khaioan2766 6 ปีที่แล้ว

    (index):1 Uncaught (in promise) LinkError: WebAssembly Instantiation: Import #5 module="go" function="runtime.scheduleCallback" error: function import requires a callable. Anyone helps me resolve this error??

    • @napoleonsantana5309
      @napoleonsantana5309 6 ปีที่แล้ว

      same issue

    • @napoleonsantana5309
      @napoleonsantana5309 6 ปีที่แล้ว

      Found a solution, dont use the wasm_exec.js in the description. Its repo has been changed. Just use the one in his project.
      github.com/golang/go/edit/master/misc/wasm/wasm_exec.js
      It worked for me.

  • @LucasRodrigues-vw7uz
    @LucasRodrigues-vw7uz 3 ปีที่แล้ว

    Woooooooow

  • @leozebul
    @leozebul 4 ปีที่แล้ว

    Interesting

  • @edwardanugent
    @edwardanugent 6 ปีที่แล้ว +1

    of course this doesn't work on windows

    • @vladmartian
      @vladmartian 6 ปีที่แล้ว

      But it does. Compile the server.go with GOARCH=amd64 and GOOS=windows and run the server. After that change the envs GOARCH=wasm GOOS=js and compile the main.go to main.wasm. Be shure to change the name of the wasm file in the index.html

  • @欧阳楚-h4e
    @欧阳楚-h4e 4 ปีที่แล้ว

    wow

  • @alexeygurzhiy
    @alexeygurzhiy ปีที่แล้ว

    Thank you very much.
    The tutorial is too legacy, but despite it I've managed to make a working project.
    You need to update next:
    Make a register of callback
    func registerCallbacks() {
    js.Global().Set("add", js.FuncOf(add))
    }
    And update your add function with next:
    func subtract(this js.Value, i []js.Value) interface{} {
    value1 := js.Global().Get("document").Call("getElementById", i[0].String()).Get("value").String()
    value2 := js.Global().Get("document").Call("getElementById", i[1].String()).Get("value").String()
    intVal1, _ := strconv.Atoi(value1)
    intVal2, _ := strconv.Atoi(value2)
    println(intVal1 - intVal2)
    js.Global().Get("document").Call("getElementById", i[2].String()).Set("value", intVal1 - intVal2)
    return (intVal1 - intVal2)