Once again: Include files in go?

76 views
Skip to first unread message

Frank Jüdes

unread,
Nov 1, 2022, 10:43:45 PM11/1/22
to golang-nuts
Hi friends, i have found a couple of threads about how to include c-headers into go-programs, but nothing that i could use for my rather unique challenge:

I have an SQL-Database in which test-cases are being defined in a couple of tables. Those test-cases will be exported by a PL/SQL program as go source-code. Basically the Database is writing a piece of go source-code in which a single variable, representing a large data-structure is being initialized. This variable should be part of a package, defining functions on that structure. For now i am just copying and pasting the generated file into the go-package using an editor, but that will not be practical for much longer, as the amount of data is increasing rapidly…
So what i am looking for is the classic c-style include:
 
package package_name

import ( … )

type …

#include GeneratedDataFromDB

func()…

it is not something my life is depending on, i can always use Linux tools to cat some files together, but a simple #include - or similar would be more elegant.
Thank you very much in advance for your help.

Christian Stewart

unread,
Nov 1, 2022, 10:49:11 PM11/1/22
to Frank Jüdes, golang-nuts
Frank,

Am I missing something - can't you just put multiple go files in the same directory?

All the go files in the directory will be combined into the same package.

This is frequently used for other codegen, like Protobuf.

Best,
Christian Stewart 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/7c1524a5-6c45-4ca8-862e-84f0b620b18fn%40googlegroups.com.

Kurtis Rader

unread,
Nov 1, 2022, 11:28:58 PM11/1/22
to Frank Jüdes, golang-nuts
I think you're looking for the "//go:generate" directive. Google "go generate" and/or read documents such as https://ehrt74.medium.com/go-generate-89b20a27f7f9 and https://go.dev/blog/generate.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/7c1524a5-6c45-4ca8-862e-84f0b620b18fn%40googlegroups.com.


--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank
Reply all
Reply to author
Forward
0 new messages