This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
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 #34 from suzuki-shunsuke/build/fix-mockserver-bina…
…ry-version build: fix mockserver binary version
- Loading branch information
Showing
6 changed files
with
167 additions
and
105 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,61 @@ | ||
package cmd | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
|
||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/suzuki-shunsuke/go-graylog" | ||
"github.com/suzuki-shunsuke/go-graylog/mockserver/exec/usecase" | ||
) | ||
|
||
var help string | ||
|
||
func init() { | ||
help = fmt.Sprintf(` | ||
graylog-mock-server - Run Graylog mock server. | ||
USAGE: | ||
graylog-mock-server [options] | ||
VERSION: | ||
%s | ||
OPTIONS: | ||
--port value port number. If you don't set this option, a free port is assigned and the assigned port number is output to the console when the mock server runs. | ||
--log-level value the log level of logrus which the mock server uses internally. (default: "info") | ||
--data value data file path. When the server runs data of the file is loaded and when data of the server is changed data is saved at the file. If this option is not set, no data is loaded and saved. | ||
--help, -h show help | ||
--version, -v print the version | ||
`, graylog.Version) | ||
} | ||
|
||
// Run runs a mock server. | ||
func Run() { | ||
var portFlag = flag.Int( | ||
"port", 0, | ||
"port number. If you don't set this option, a free port is assigned and the assigned port number is output to the console when the mock server runs.") | ||
var dataFlag = flag.String( | ||
"data", "", | ||
"data file path. When the server runs data of the file is loaded and when data of the server is changed data is saved at the file. If this option is not set, no data is loaded and saved.") | ||
var logLevelFlag = flag.String( | ||
"log-level", "info", | ||
`the log level of logrus which the mock server uses internally. (default: "info")`) | ||
var helpFlag = flag.Bool("help", false, "Show help.") | ||
var versionFlag = flag.Bool("version", false, "Print the version.") | ||
flag.Parse() | ||
|
||
if *helpFlag { | ||
fmt.Println(help) | ||
return | ||
} | ||
if *versionFlag { | ||
fmt.Println(graylog.Version) | ||
return | ||
} | ||
|
||
if err := usecase.Run(*dataFlag, *logLevelFlag, *portFlag); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
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,61 @@ | ||
package usecase | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/pkg/errors" | ||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/suzuki-shunsuke/go-graylog/mockserver" | ||
"github.com/suzuki-shunsuke/go-graylog/mockserver/store/plain" | ||
) | ||
|
||
// Run runs a mock server. | ||
func Run(dataPath, logLevel string, port int) error { | ||
var ( | ||
server *mockserver.Server | ||
err error | ||
) | ||
if port == 0 { | ||
server, err = mockserver.NewServer( | ||
"", plain.NewStore(dataPath)) | ||
} else { | ||
server, err = mockserver.NewServer( | ||
fmt.Sprintf(":%d", port), plain.NewStore(dataPath)) | ||
} | ||
if err != nil { | ||
return errors.Wrap(err, "failed to create a mock server") | ||
} | ||
lvl, err := log.ParseLevel(logLevel) | ||
if err != nil { | ||
return fmt.Errorf( | ||
`invalid log-level %s. | ||
log-level must be any of debug|info|warn|error|fatal|panic`, logLevel) | ||
} | ||
|
||
server.Logger().SetLevel(lvl) | ||
if err := server.Load(); err != nil { | ||
return errors.Wrap(err, fmt.Sprintf("failed to load data at %s", dataPath)) | ||
} | ||
server.Start() | ||
defer server.Close() | ||
server.Logger().Infof( | ||
"Start Graylog mock server: %s\nCtrl + C to stop server", server.Endpoint()) | ||
signalChan := make(chan os.Signal, 1) | ||
signal.Notify( | ||
signalChan, syscall.SIGHUP, syscall.SIGINT, | ||
syscall.SIGTERM, syscall.SIGQUIT) | ||
exitChan := make(chan int) | ||
go func() { | ||
for { | ||
<-signalChan | ||
exitChan <- 0 | ||
} | ||
}() | ||
|
||
<-exitChan | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Usage | ||
# bash script/tag.sh v0.6.1 | ||
|
||
if [ $# -gt 1 ]; then | ||
echo "too many arguments" > /dev/stderr | ||
echo 'Usage tag.sh $TAG' > /dev/stderr | ||
exit 1 | ||
fi | ||
|
||
if [ $# -lt 1 ]; then | ||
echo "TAG argument is required" > /dev/stderr | ||
echo 'Usage tag.sh $TAG' > /dev/stderr | ||
exit 1 | ||
fi | ||
|
||
TAG=$1 | ||
echo "TAG: $TAG" | ||
VERSION=${TAG#v} | ||
|
||
if [ "$TAG" = "$VERSION" ]; then | ||
echo "TAG must start with 'v'" | ||
exit 1 | ||
fi | ||
|
||
echo "cd `dirname $0`/.." | ||
cd `dirname $0`/.. | ||
|
||
echo "create version.go" | ||
cat << EOS > version.go | ||
package domain | ||
// Version is the go-graylog's version. | ||
const Version = "$VERSION" | ||
EOS | ||
|
||
git add version.go | ||
npm run release -- --release-as $TAG |
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,4 @@ | ||
package graylog | ||
|
||
// Version is the go-graylog's version. | ||
const Version = "0.6.1" |