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 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧