Skip to content

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

Open

Description

@SunnysideAaron

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

Activity

  1. SunnysideAaron commented on Feb 10, 2025

    @SunnysideAaron
    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.

  2. raphael commented on Feb 16, 2025

    @raphael
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions