Skip to content

Commit

Permalink
Merge pull request #58 from mattn/windows
Browse files Browse the repository at this point in the history
Windows
  • Loading branch information
izumin5210 authored Apr 16, 2018
2 parents df11cb8 + 4ab6895 commit 5ab6548
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 11 deletions.
19 changes: 16 additions & 3 deletions cmd/grapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package main

import (
"fmt"
"io"
"os"
"runtime"

"github.com/izumin5210/grapi/pkg/grapicmd"
"github.com/izumin5210/grapi/pkg/grapicmd/cmd"
"github.com/mattn/go-colorable"
)

var (
Expand All @@ -16,11 +19,21 @@ var (

releaseType string

inReader = os.Stdin
outWriter = os.Stdout
errWriter = os.Stderr
inReader = os.Stdin
outWriter io.Writer = os.Stdout
errWriter io.Writer = os.Stderr
)

func init() {
if runtime.GOOS == "windows" {
outWriter = colorable.NewColorableStdout()
errWriter = colorable.NewColorableStderr()
}
if name == "" {
name = "grapi"
}
}

func main() {
cwd, err := os.Getwd()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/grapicmd/internal/module/generator/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (g *serviceGenerator) createParams(path string, resName string, methodNames
}

protoPackageChunks := []string{}
for _, pkg := range strings.Split(filepath.Join(importPath, "api", filepath.Dir(path)), "/") {
for _, pkg := range strings.Split(filepath.ToSlash(filepath.Join(importPath, "api", filepath.Dir(path))), "/") {
chunks := strings.Split(strings.Replace(pkg, "-", "_", -1), ".")
for i := len(chunks) - 1; i >= 0; i-- {
protoPackageChunks = append(protoPackageChunks, chunks[i])
Expand Down Expand Up @@ -245,7 +245,7 @@ func (g *serviceGenerator) createParams(path string, resName string, methodNames
},
PbGo: servicePbGoParams{
PackageName: pbgoPackageName,
PackagePath: filepath.Join(importPath, pbgoPackagePath),
PackagePath: filepath.ToSlash(filepath.Join(importPath, pbgoPackagePath)),
},
Go: serviceGoParams{
Package: packageName,
Expand Down
7 changes: 6 additions & 1 deletion pkg/grapicmd/internal/module/script/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package script

import (
"path/filepath"
"runtime"
"sort"

"github.com/pkg/errors"
Expand Down Expand Up @@ -42,12 +43,16 @@ func (f *scriptLoader) Load(dir string) error {
srcPaths = append(srcPaths, filepath.Join(dir, name))
}
name := filepath.Base(dir)
ext := ""
if runtime.GOOS == "windows" {
ext = ".exe"
}
f.scripts[name] = &script{
fs: f.fs,
commandFactory: f.commandFactory,
srcPaths: srcPaths,
name: name,
binPath: filepath.Join(f.binDir, name),
binPath: filepath.Join(f.binDir, name+ext),
rootDir: f.rootDir,
}
f.names = append(f.names, name)
Expand Down
2 changes: 1 addition & 1 deletion pkg/grapicmd/internal/usecase/execute_protoc_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (u *executeProtocUsecase) executeProtoc(protoPath string) error {
return errors.WithStack(err)
}
for _, cmd := range cmds {
out, err := u.commandFactory.Create(cmd).AddEnv("PATH", u.binDir+":"+os.Getenv("PATH")).SetDir(u.rootDir).Exec()
out, err := u.commandFactory.Create(cmd).AddEnv("PATH", u.binDir+string(filepath.ListSeparator)+os.Getenv("PATH")).SetDir(u.rootDir).Exec()
if err != nil {
return errors.Wrapf(err, "failed to execute module: %s", string(out))
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/grapicmd/util/fs/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func init() {
// GetImportPath creates the golang package path from the given path.
func GetImportPath(rootPath string) (importPath string, err error) {
for _, gopath := range filepath.SplitList(BuildContext.GOPATH) {
prefix := filepath.Join(gopath, "src") + "/"
prefix := filepath.Join(gopath, "src") + string(filepath.Separator)
// FIXME: should not use strings.HasPrefix
if strings.HasPrefix(rootPath, prefix) {
importPath = strings.Replace(rootPath, prefix, "", 1)
importPath = filepath.ToSlash(strings.Replace(rootPath, prefix, "", 1))
break
}
}
Expand Down Expand Up @@ -74,7 +74,8 @@ func LookupRoot(fs afero.Fs, dir string) (string, bool) {
return dir, true
}

if dir == "/" {
p := dir[len(filepath.VolumeName(dir)):]
if p == string(filepath.Separator) {
return "", false
}

Expand Down
10 changes: 9 additions & 1 deletion pkg/grapiserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net"
"os"
"path/filepath"
pkg_runtime "runtime"
"time"

"github.com/grpc-ecosystem/go-grpc-middleware"
Expand All @@ -13,7 +14,7 @@ import (
)

func createDefaultConfig() *Config {
return &Config{
config := &Config{
GrpcInternalAddr: &Address{
Network: "unix",
Addr: "tmp/server.sock",
Expand All @@ -24,6 +25,13 @@ func createDefaultConfig() *Config {
},
MaxConcurrentStreams: 1000,
}
if pkg_runtime.GOOS == "windows" {
config.GrpcInternalAddr = &Address{
Network: "tcp",
Addr: ":5050",
}
}
return config
}

// Address represents a network end point address.
Expand Down

0 comments on commit 5ab6548

Please sign in to comment.