GoogleCloudPlatform / go-endpoints

Cloud Endpoints for Go
https://go-endpoints.appspot.com
Apache License 2.0
255 stars 56 forks source link

Calling Print functions using fmt in init() #102

Open wiless opened 9 years ago

wiless commented 9 years ago

WhenPrint methods from fmt are called during the init() For e.g in samples/helloworld/helloworld.go, the API Service discovery fails. http://localhost:8080/_ah/api/discovery/v1/apis returns

{"error": {"message": "BackendService.getApiConfigs Error"}}

This also disables functionality of the api explorer http://localhost:8080/_ah/api/explorer

init() from the helloworld.go

func init() {

    api, err := endpoints.RegisterService(&GreetingService{},
        "greetings", "v1", "Greetings API", true)
    if err != nil {
        log.Fatalf("Register service: %v", err)
    } else {
        log.Printf("API registered %v", api)
    }
    endpoints.HandleHTTP()
}

works but the following init() fails

func init() {

    api, err := endpoints.RegisterService(&GreetingService{},
        "greetings", "v1", "Greetings API", true)
    if err != nil {
        log.Fatalf("Register service: %v", err)
    } else {
        fmt.Printf("API registered %v", api)
    }
    endpoints.HandleHTTP()
}