-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from MrAzharuddin/feat-swagger
Feat swagger
- Loading branch information
Showing
5 changed files
with
76 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package golang | ||
|
||
import "os/exec" | ||
|
||
// commandExists checks if a command exists in the system. | ||
// cmd: the command to check. | ||
// bool: true if the command exists, false otherwise. | ||
func commandExists(cmd string) bool { | ||
_, err := exec.LookPath(cmd) | ||
return err == nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package golang | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os/exec" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// RunSwag runs swag with args passed on generated code present in the directory passed. | ||
func RunSwag(directoryName string) error { | ||
swagCommand := "swag" | ||
if commandExists(swagCommand) { | ||
args := []string{"init", "--parseDependency", "--parseInternal"} | ||
command := exec.Command(swagCommand, args...) | ||
command.Dir = directoryName | ||
var stdErr bytes.Buffer | ||
command.Stderr = &stdErr | ||
var stdOut bytes.Buffer | ||
command.Stdout = &stdOut | ||
if err := command.Run(); err != nil { | ||
log.Errorf("%s\n", err) | ||
log.Errorf("%s\n", stdErr.String()) | ||
log.Errorf("%s\n", stdOut.String()) | ||
return err | ||
} | ||
if len(stdErr.String()) > 0 { | ||
log.Errorf("%s\n", stdErr.String()) | ||
} | ||
if len(stdOut.String()) > 0 { | ||
log.Infof("%s\n", stdOut.String()) | ||
} | ||
return nil | ||
} else { | ||
return fmt.Errorf("%s command doesn't exist. Please install swag using https://github.com/swaggo/swag?tab=readme-ov-file#getting-started.\nInstalled, and still facing issue? Please check https://github.com/swaggo/swag/issues/197", swagCommand) | ||
} | ||
} |