Search code examples
godocstring

Access package comment from inside Go program?


Is it possible to get package comment from inside of Go program? The equivalent Python code:

#!/usr/bin/env python
"""
Program v1.0
"""
print(__doc__)

Solution

  • Go is not an interpreted language. The source code representation of a program is not part of a compiled Go program and cannot be generated from a compiled Go program. What you want is not possible without external tools that embed the parts of the source you want into the binary.