Go的http服务器可以编译打字稿吗?

Currently I have a NodeJS Application that starts an http server with client side code that is written in TypeScript and using Angular 2.

is it possible to do the same in Go ?

I tried googling for TypeScript and Go and didn't find anything relevant.

should I have nodeJS installed, install typescript compiler with npm install -g typescript, compile the typescripts whenever I change them and provide the javascript files on my Go Server ?

any information regarding the issue would be greatly appreciated.

thanks!

You have a couple of options here:

  1. Do the translation client side by including the typescript library in your html and loading <script type='text/typescript' src="/myscript.ts"></script>

  2. Run tsc -w in the background and just serve the compiled javascript. You could launch it when your app starts so it dies with your app as well. I only run tsc in "dev" mode, and check in the js files for production use.

  3. Run tsc on demand when you receive requests, and cache results. Probably pretty tricky to detect changes but there are packages to help with that.