Rename environment variable for Go to post-process file (#1091)

* renmae Go post process file env variable

* add back samples/client/petstore/c/libcurl.licence

* keep go samples up-to-date

* update go petstore samples

* update go samples without formatting
This commit is contained in:
William Cheng
2018-10-01 21:24:32 +08:00
committed by GitHub
parent dcc0b5e772
commit 2b87b309ad
47 changed files with 437 additions and 361 deletions

View File

@@ -115,6 +115,15 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
.defaultValue(Boolean.TRUE.toString()));
}
@Override
public void processOpts() {
super.processOpts();
if (StringUtils.isEmpty(System.getenv("GO_POST_PROCESS_FILE"))) {
LOGGER.info("Environment variable GO_POST_PROCESS_FILE not defined so Go code may not be properly formatted. To define it, try `export GO_POST_PROCESS_FILE=\"/usr/local/bin/gofmt -w\"` (Linux/Mac)");
}
}
/**
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping
* those terms here. This logic is only called if a variable matches the reserved words
@@ -613,9 +622,9 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
return;
}
String goFmtPath = System.getenv("GO_FMT_PATH");
if (StringUtils.isEmpty(goFmtPath)) {
return; // skip if GO_FMT_PATH env variable is not defined
String goPostProcessFile = System.getenv("GO_POST_PROCESS_FILE");
if (StringUtils.isEmpty(goPostProcessFile)) {
return; // skip if GO_POST_PROCESS_FILE env variable is not defined
}
// only procees the following type (or we can simply rely on the file extension to check if it's a Go file)
@@ -632,16 +641,17 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
// only process files with go extension
if ("go".equals(FilenameUtils.getExtension(file.toString()))) {
// currently only support "gofmt -w yourcode.go"
// another way is "go fmt path/to/your/package"
String command = goFmtPath + " -w " + file.toString();
// e.g. "gofmt -w yourcode.go"
// e.g. "go fmt path/to/your/package"
String command = goPostProcessFile + " " + file.toString();
try {
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
if (p.exitValue() != 0) {
LOGGER.error("Error running the command ({}). Exit code: {}", command, p.exitValue());
int exitValue = p.waitFor();
if (exitValue != 0) {
LOGGER.error("Error running the command ({}). Exit code: {}", command, exitValue);
} else {
LOGGER.info("Successfully executed: " + command);
}
LOGGER.info("Successfully executed: " + command);
} catch (Exception e) {
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
}

View File

@@ -71,10 +71,6 @@ public class GoClientCodegen extends AbstractGoCodegen {
public void processOpts() {
super.processOpts();
if (StringUtils.isEmpty(System.getenv("GO_FMT_PATH"))) {
LOGGER.info("Environment variable GO_FMT_PATH not defined so Go code may not be properly formatted. To define it, try 'export GO_FMT_PATH=/usr/local/bin/gofmt' (Linux/Mac)");
}
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
} else {

View File

@@ -106,10 +106,6 @@ public class GoGinServerCodegen extends AbstractGoCodegen {
public void processOpts() {
super.processOpts();
if (StringUtils.isEmpty(System.getenv("GO_FMT_PATH"))) {
LOGGER.info("Environment variable GO_FMT_PATH not defined so Go code may not be properly formatted. To define it, try 'export GO_FMT_PATH=/usr/local/bin/gofmt' (Linux/Mac)");
}
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
} else {

View File

@@ -90,10 +90,6 @@ public class GoServerCodegen extends AbstractGoCodegen {
public void processOpts() {
super.processOpts();
if (StringUtils.isEmpty(System.getenv("GO_FMT_PATH"))) {
LOGGER.info("Environment variable GO_FMT_PATH not defined so Go code may not be properly formatted. To define it, try 'export GO_FMT_PATH=/usr/local/bin/gofmt' (Linux/Mac)");
}
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
} else {