Skip to content

basic example on windows messes up import path in generated file #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
SunnysideAaron opened this issue Feb 10, 2025 · 2 comments
Open

Comments

@SunnysideAaron
Copy link

I'm on windows. Working through the basic examples readme. There appears to be a problem with generating paths in the code on windows.

$Env:GOPATH

returns

C:\Users\fuzzy\go

I run the following commands

cd c:\Working\goexamples
gonew goa.design/examples/basic@latest
cd basic
goa gen goa.design/examples/basic/design -o $GOPATH/src/goa.design/examples/basic

I am then getting the following error

exit status 1
C:\src\goa.design\examples\basic\gen\calc\service.go:15:16: unknown escape sequence
C:\src\goa.design\examples\basic\gen\calc\service.go:15:20: unknown escape sequence
C:\src\goa.design\examples\basic\gen\calc\service.go:15:31: unknown escape sequence
C:\src\goa.design\examples\basic\gen\calc\service.go:15:46: unknown escape sequence

========
Content:
// Code generated by goa v3.19.1, DO NOT EDIT.
//
// calc service
//
// Command:
// $ goa gen goa.design/examples/basic/design -o /src/goa.design/examples/basic

package calc

import (
        "context"
        "io"
        goa "goa.design/goa/v3/pkg"
        "goa.design/goa/v3/security"
        calcviews "C:\src\goa.design\examples\basic\gen/calc/views"
)


// The calc service performs operations on numbers
type Service interface {
        // Multiply implements multiply.
                Multiply(context.Context, *MultiplyPayload) (res int, err error)
}

// APIName is the name of the API as defined in the design.
const APIName = "calc"

// APIVersion is the version of the API as defined in the design.
const APIVersion = "0.0.1"

// ServiceName is the name of the service as defined in the design. This is the
// same value that is set in the endpoint request contexts under the ServiceKey
// key.
const ServiceName = "calc"

// MethodNames lists the service method names as defined in the design. These
// are the same values that are set in the endpoint request contexts under the
// MethodKey key.
var MethodNames = [1]string{ "multiply",  }
// MultiplyPayload is the payload type of the calc service multiply method.
type MultiplyPayload struct {
        // Left operand
        A int
        // Right operand
        B int
}

Notice the last line of the import()

calcviews "C:\src\goa.design\examples\basic\gen/calc/views"

notice the slashes are mixed \ and /
also c:\ is not my gopath

@SunnysideAaron
Copy link
Author

I'm guessing most everyone is running goa on some linux docker image. Which I will be as well but didn't start there for learning. It's probably just something along the way not handling paths correctly.

@raphael
Copy link
Member

raphael commented Feb 16, 2025

Thank you for reporting the issue! While most people probably use Goa on Linux/Mac it also ought to work natively on Windows (the tests are run on Windows for every PR). I wonder if the issue is the argument given via -o This argument should be a file path - not a Go import path. So on Windows it should be:

goa gen goa.design/examples/basic/design -o c:\src\goa.desig\examples\basic

Do you still get the error with the above command line? Goa relies on the standard Go library golang.org/x/tools/go/packages to compute the Package path for the generated import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants