Skip to content

Go template implementation in Java

License

Notifications You must be signed in to change notification settings

verils/gotemplate4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang Template Engine for Java

Testing

Evaluate go templates and make textual output.

Before then, there is another fine library with a name not so intuitive: Java Template Engine, you can choose that if you like.

This project is for experimental purpose, please DON'T USE IN PRODUCTION for now because the support for complex number and builtin functions is incomplete. Wish I can finish them ASAP.

You can see the changelog to know what's happening.

Requirements

Java Version: >= 1.8

No other dependency required except for Vanilla Java

Installation

For Maven, you can simply add dependency:

<dependency>
    <groupId>io.github.verils</groupId>
    <artifactId>gotemplate4j</artifactId>
    <version>0.3.1</version>
</dependency>

Usage

// Create a user as the input data
User user = new User();
user.setName("Bob");

// Prepare you template
Template template = new Template("demo");
template.parse("Hello, {{ .Name }}!");

// Execute and print out the result text
StringWriter writer = new StringWriter();
template.execute(writer, user);
System.out.print(writer.toString());  // "Hello Bob!"

Limitations

  • The format of print functions in Java are different from Golang
  • Achieved only a few built-in functions
  • The procedure of PipeNode is weak

Waht is Next?

  • Support complex number format
  • Support all built-in functions in Golang
  • Complete PipeNode for all types of identifiers

About

Go template implementation in Java

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages