duankuang7928 2014-08-23 23:59
浏览 207
已采纳

如何集成Golang后端和Javascript(three.js)前端?

I would like to write a 3D application using Golang, my favorite programming language. However, I would prefer not to use native OpenGL directly as the graphical frontend as this would entail a larger learning curve than I'm willing to tolerate. Additionally, I don't really want to use a Golang game engine like go:ngine.

After doing some research I found out about the amazing WebGL Javascript library three.js and I was so intrigued that I completed an introductory Javascript course in a few hours. I'm not really a web developer at all, so I'm wondering how practical it would be for me to write my application primarily in Go but with a three.js frontend.

Some specific questions:

  • Is it worthwhile / practical to use Javascript/three.js as a frontend to a Golang server like this?
  • If it is worthwhile, where can I look to learn how to integrate the two cleanly?
  • If it isn't really worthwhile, which alternatives do I have?

Thanks, any response appreciated.

Edit:

Do you plan to make operations on geometry in Go, possibly in realtime and communicate with your Javascript layer using Websockets?

Yes, this is what I'm thinking now. I'm intending my (Golang) program to generate streams of vertices and triangles based on a few parameters from the user. Each "structure" is generated all at once after the users supply their parameters (which I see as slider bars + input boxes on a Javascript frontend).

Here's an example of something the Go program might generate, plotted in GNUPlot: pic
(source: alexozer.com)

If this is the case you underestimate Javascript a bit. You should write most of your application in Javascript and use Go as a classical backend service layer like user accounts, persisting state, etc.

I'd be fine with doing that, except for these reasons:

  • The core generating process fundamentally depends on Goroutines and channels
  • I know close to nothing about web development, including frontend and backend

So I suppose I'm asking about the implementation details of one of these three possibilities:

Writing most of the program, including the generator, in JS, and a minimal backend in Go Writing most of the program in Go and using JS just as a graphical frontend Something else?
  • 写回答

2条回答 默认 最新

  • doufud21086 2014-08-24 13:58
    关注

    I recommend leaving out the whole Websocket aspect because it's only a possible optimization (and maybe not even that).

    If you need to depend on Go's concurrency model then go for it, write your component in Go, then a Webserver in Go that takes parameters coming from an HTML request, uses them to compute the result and sends back the data in a JSON format.

    On the frontend you will then only focus on sending this request when the user changed a parameter and for displaying of the JSON data you can use ThreeJS right away.

    You'll still have to learn a bit of web development and Javascript though. But hey, they say the web is the future ;-)

    I think it's the way to go for your case because your application operates in a quite strict request-result way.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题