Go: proposal: Go 2: Permit running code at compile-time using "comptime" keyword

Created on 22 May 2020  路  4Comments  路  Source: golang/go

Problem

I want to read in the content of files while compiling time to simplify the shipping of template files with a binary.

Solution

using the comptime keyword to run arbitrary code at compilation-time.

Ref: https://ziglang.org/documentation/master/#Introducing-the-Compile-Time-Concept

Design idea

func main() {
    content := comptime os.Open("./code.json")
   ....
}
Go2 LanguageChange Proposal Proposal-FinalCommentPeriod

Most helpful comment

We aren't going to permit arbitrary code to run at compile time.

The specific topic of embedding files in a compiled binary is #35950.

All 4 comments

We aren't going to permit arbitrary code to run at compile time.

The specific topic of embedding files in a compiled binary is #35950.

Also there is go generate which should be used instead for code generation.

For the reasons mentioned above, this is a likely decline. Leaving open for four weeks for final comments.

No further comments.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rakyll picture rakyll  路  3Comments

natefinch picture natefinch  路  3Comments

rsc picture rsc  路  3Comments

Miserlou picture Miserlou  路  3Comments

OneOfOne picture OneOfOne  路  3Comments