blob: 87ba6f903763ac273f1e7705f42304f4e1e6df99 [file] [log] [blame]
Jens Geyer0853ab62013-12-17 21:38:44 +01001Thrift Go Software Library
Jens Geyer0e87c462013-06-18 22:25:07 +02002
3License
4=======
5
6Licensed to the Apache Software Foundation (ASF) under one
7or more contributor license agreements. See the NOTICE file
8distributed with this work for additional information
9regarding copyright ownership. The ASF licenses this file
10to you under the Apache License, Version 2.0 (the
11"License"); you may not use this file except in compliance
12with the License. You may obtain a copy of the License at
13
14 http://www.apache.org/licenses/LICENSE-2.0
15
16Unless required by applicable law or agreed to in writing,
17software distributed under the License is distributed on an
18"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19KIND, either express or implied. See the License for the
20specific language governing permissions and limitations
21under the License.
22
Jens Geyer0853ab62013-12-17 21:38:44 +010023
Jens Geyer0e87c462013-06-18 22:25:07 +020024Using Thrift with Go
25====================
26
27In following Go conventions, we reccomend you use the 'go' tool to install
28Thrift for go.
29
Jens Geyer0853ab62013-12-17 21:38:44 +010030 $ go get git.apache.org/thrift.git/lib/go/thrift
Jens Geyer0e87c462013-06-18 22:25:07 +020031
32Will install the last stable release.
Jens Geyer0853ab62013-12-17 21:38:44 +010033
34
35A note about optional fields
36============================
37
38The thrift-to-Go compiler tries to represent thrift IDL structs as Go structs.
39We must be able to distinguish between optional fields that are set to their
40default value and optional values which are actually unset, so the generated
41code represents optional fields via pointers.
42
43This is generally intuitive and works well much of the time, but Go does not
44have a syntax for creating a pointer to a constant in a single expression. That
45is, given a struct like
46
47 struct SomeIDLType {
48 OptionalField *int32
49 }
50
51, the following will not compile:
52
53 x := &SomeIDLType{
54 OptionalField: &(3),
55 }
56
57(Nor is there any other syntax that's built in to the language)
58
59As such, we provide some helpers that do just this under lib/go/thrift/. E.g.,
60
61 x := &SomeIDLType{
62 OptionalField: thrift.Int32Ptr(3),
63 }
64
65And so on. The code generator also creates analogous helpers for user-defined
66typedefs and enums.