glo
github.com/soheilhy/glosure
go get github.com/soheilhy/glosure
glo

github.com/soheilhy/glosure

Closure Compiler for the Go programming language.

by Soheil Hassas Yeganeh

v0.0.0-20140530143641-592acec473c0 (see all)License:Apache-2.0
go get github.com/soheilhy/glosure
Readme

Glosure: Closure Compiler for Go

Glosure is a simple http.Handler for compiling JavaScript using the Closure Compiler. Glosure can use either the closure compiler application (requires Java Runtime Environment) or the closure REST API (used if java is not in $PATH).

Note that the REST API has limitations and is not be suitable for large-scale JavaScript projects.

Installation:

# go get github.com/soheilhy/glosure

Example:

First create a closure compiler, and then serve HTTP requests:

cc := glosure.NewCompiler("./example/js/")
// Set compiler options.
http.Handle("/", glosure.GlosureServer(cc))
http.ListenAndServe(":8080", nil);

Or even simpler if you do not need to customize the compiler:

http.Handle("/", glosure.GlosureServerWithRoot("./example/js/"))
http.ListenAndServe(":8080", nil);

Or to enforce using the closure REST API:

cc := glosure.NewCompiler("./example/js/")
cc.UseClosureApi = true
http.Handle("/", glosure.GlosureServer(cc))
http.ListenAndServe(":8080", nil);

GlosureServer serves only the requests for compiled JavaScript (by default *.min.js) and returns error otherwise. For example, http://localhost:8080/sample.min.js returns the compiled version of ./example/js/sample.js, but dialing http://localhost:8080/sample.js results in a 404. You can change this behavior by setting a customized handler in cc.ErrorHandler.

For a more comprehensive example, take a look at example/server.go. You can run the example by:

# go run server.go --logtostderr -v=1

GitHub Stars

12

LAST COMMIT

8yrs ago

MAINTAINERS

0

CONTRIBUTORS

1

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
v0.0.0-20140530143641-592acec473c0
2yrs ago
No alternatives found
No tutorials found
Add a tutorial