go get github.com/tourmind-com/tmsx-go # once published — source repo: github.com/tourmind-com/tmsx-goSource repo (post-extract from tms-doc): tourmind-com/tmsx-go.
Spec + test cases live in tourmind-com/tmsx-platform per ADR-002.
package main
import (
"context"
"fmt"
"time"
tmsx "github.com/tourmind-com/tmsx-go"
"github.com/tourmind-com/tmsx-go/hotel"
)
func main() {
client, err := tmsx.NewClient(
tmsx.WithAgentCode("tms_test"),
tmsx.WithUsername("tms_test"),
tmsx.WithPassword("tms_test"),
)
if err != nil { panic(err) }
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
regions, err := client.Hotel.ListRegions(ctx, &hotel.ListRegionsRequest{CountryCode: "CN"})
if err != nil { panic(err) }
for _, region := range regions.RegionListResult.Regions {
fmt.Println(region.RegionID, region.Name)
}
}The SDK injects the TMSX auth scheme (X-Agent-Code / X-Username headers + the
RequestHeader body envelope with Password, RequestTime, TransactionID) on
every request — see https://github.com/tourmind-com/tmsx-platform/blob/main/AUTH.md. Callers never touch RequestHeader.
context.Contextfirst arg on every method — supports cancellation + deadlines.- Functional options (
tmsx.WithAgentCode("..."),tmsx.WithBaseURL("...")) — additive without breaking changes. client.Hotel.SearchHotel(ctx, &hotel.SearchHotelRequest{...})— namespace per API family, leaves room forclient.Flight.*later.http.Clientinjection (tmsx.WithTransport(myRoundTripper)) — plug in retries, tracing, or test doubles.
The TMSX API returns failures as Error.ErrorCode inside an HTTP 200 body.
The SDK translates this:
import "errors"
_, err := client.Hotel.ListRegions(ctx, &hotel.ListRegionsRequest{})
if err != nil {
var authErr *tmsx.AuthError
if errors.As(err, &authErr) {
// rotate credentials
}
if errors.Is(err, tmsx.ErrAuth) {
// same sentinel match
}
var apiErr *hotel.APIError
if errors.As(err, &apiErr) {
log.Println(apiErr.Code, apiErr.Message, apiErr.TransactionID)
}
}tmsx-go/
├── go.mod
├── client.go # tmsx.Client + functional options
├── auth.go # http.RoundTripper that injects auth
├── errors.go # Error / AuthError / ValidationError / ClientError
├── hotel/
│ ├── service.go # 9 operations
│ └── types.go # request/response structs
└── examples/canonical-flow/main.go
# (you are already in tmsx-go/ — no cd needed)
go vet ./...
go build ./...
go run ./examples/canonical-flow # hits the public sandbox🟡 Alpha.
- No retry middleware yet — plug your own via
tmsx.WithTransport(yourRoundTripper)for now. - Pagination is manual (
Page+PageSizeinQueryBookingsRequest); idiomatic iterator helpers later. - Response sub-trees with many optional fields ship as
json.RawMessageto avoid bloat — unmarshal yourself for deep typing. Full typed structs come once we exercise them via the test harness.