BuildBindingGo builds Go-bindings of a library's API
(component ComponentDefinition, outputFolder string, outputFolderExample string)
| 43 | |
| 44 | // BuildBindingGo builds Go-bindings of a library's API |
| 45 | func BuildBindingGo(component ComponentDefinition, outputFolder string, outputFolderExample string) error { |
| 46 | forceRecreation := false |
| 47 | |
| 48 | NameSpace := component.NameSpace |
| 49 | LibraryName := component.LibraryName |
| 50 | BaseName := component.BaseName |
| 51 | |
| 52 | GoIntfName := path.Join(outputFolder, BaseName+".go") |
| 53 | log.Printf("Creating \"%s\"", GoIntfName) |
| 54 | gofile, err := CreateLanguageFile(GoIntfName, " ") |
| 55 | if err != nil { |
| 56 | return err |
| 57 | } |
| 58 | |
| 59 | GoImplName := path.Join(outputFolder, BaseName+"_impl.go") |
| 60 | log.Printf("Creating \"%s\"", GoImplName) |
| 61 | goimplfile, err := CreateLanguageFile(GoImplName, " ") |
| 62 | if err != nil { |
| 63 | return err |
| 64 | } |
| 65 | |
| 66 | gofile.WriteCLicenseHeader(component, |
| 67 | fmt.Sprintf("This is an autogenerated Go wrapper file in order to allow an easy\n use of %s", LibraryName), |
| 68 | true) |
| 69 | goimplfile.WriteCLicenseHeader(component, |
| 70 | fmt.Sprintf("This is an autogenerated Go implementation file in order to allow an easy\n use of %s", LibraryName), |
| 71 | true) |
| 72 | |
| 73 | err = buildGoWrapper(component, gofile, goimplfile) |
| 74 | if err != nil { |
| 75 | return err |
| 76 | } |
| 77 | |
| 78 | if len(outputFolderExample) > 0 { |
| 79 | goExample := path.Join(outputFolderExample, NameSpace+"_example"+".go") |
| 80 | if forceRecreation || !FileExists(goExample) { |
| 81 | log.Printf("Creating \"%s\"", goExample) |
| 82 | goExampleFile, err := CreateLanguageFile(goExample, " ") |
| 83 | if err != nil { |
| 84 | return err |
| 85 | } |
| 86 | goExampleFile.WriteCLicenseHeader(component, |
| 87 | fmt.Sprintf("This is an autogenerated Go application that demonstrates the\n usage of the Go bindings of %s", LibraryName), |
| 88 | true) |
| 89 | buildGoExample(component, goExampleFile, outputFolder) |
| 90 | } else { |
| 91 | log.Printf("Omitting recreation of Go example file \"%s\"", goExample) |
| 92 | } |
| 93 | } |
| 94 | return nil |
| 95 | } |
| 96 | |
| 97 | func buildGoExample(component ComponentDefinition, w LanguageWriter, outputFolder string) { |
| 98 | packageName := component.BaseName |
no test coverage detected