2

Hy, I have some problems with the Go endpoints and Dart client library. I use the Go library https://github.com/crhym3/go-endpoints and the dart generator https://github.com/dart-lang/discovery_api_dart_client_generator

The easy examples works fine. But they show never how to use time.Time. In my project, I have a struct with a field:

Created time.Time      `json:"created"`

The output in the explorer looks like this:

"created": "2014-12-08T20:42:54.299127593Z",

When i use it in the dart client library, I get the error

FormatException: Invalid date format 2014-12-08T20:53:56.346129718Z

Should I really format every time fields in the go app (Format Timestamp in outgoing JSON in Golang?)? My research come to that the dart accept something: t.Format(time.RFC3339) >> 2014-12-08T20:53:56Z

Second problem, if comment out the Created field or leave it blank. I get a other error:

The null object does not have a method 'map'.

NoSuchMethodError: method not found: 'map' Receiver: null Arguments: [Closure: (dynamic) => dynamic]

But I can't figure it out which object is null. I'm not sure if I'm using the Dart client correct

import 'package:http/browser_client.dart' as http;
...
var nameValue = querySelector('#name').value;
var json = {'name':nameValue};
LaylistApi api = new LaylistApi(new http.BrowserClient());
api.create(new NewLayListReq.fromJson(json)).then((LayList l) {
  print(l);
}).catchError((e) {
  querySelector('#err-message').innerHtml=e.toString();
});

Does anyone know of a larger project on github with Go endpoint and Dart?

Thanks for any advice

UPDATE[2014-12-11]:

I fixed the

NoSuchMethodError with the correct discovery url https://constant-wonder-789.appspot.com/_ah/api/discovery/v1/apis/greeting/v1/rest

The problem with the time FormatExcetion still open, but I'm one step further. If i create a new item, it doesn' work. But if I load the items from the datastore and send it back, this works.

I guess this can be fixed with implementing Marshaler interface, thanks Alex. I will update my source soon.

See my example: http://constant-wonder-789.appspot.com/

The full source code: https://github.com/cloosli/greeting-example

Community
  • 1
  • 1
  • 2
    You can create a DateFormat object in dart and parse the go date strings using this: See [DateFormat.parse()](http://www.dartdocs.org/documentation/intl/0.11.11/index.html#intl/intl.DateFormat@id_parse) in the [intl](https://pub.dartlang.org/packages/intl) package. – Greg Lowe Dec 09 '14 at 21:11
  • Or you could change how time.Time gets formatted on the backend by implementing Marshaler interface: https://github.com/crhym3/go-endpoints/wiki/Tips-%26-Tricks – alex Dec 09 '14 at 21:30

0 Answers0