Skip to content

Repository files navigation

tmsx-go · Go SDK for the Tourmind TMSX hotel API

go get github.com/tourmind-com/tmsx-go        # once published — source repo: github.com/tourmind-com/tmsx-go

Source repo (post-extract from tms-doc): tourmind-com/tmsx-go. Spec + test cases live in tourmind-com/tmsx-platform per ADR-002.

Quick start

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.

Idioms

  • context.Context first 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 for client.Flight.* later.
  • http.Client injection (tmsx.WithTransport(myRoundTripper)) — plug in retries, tracing, or test doubles.

Errors

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)
    }
}

Layout

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

Verifying

# (you are already in tmsx-go/ — no cd needed)
go vet ./...
go build ./...
go run ./examples/canonical-flow      # hits the public sandbox

Status

🟡 Alpha.

Known limitations (matching Python + TS SDKs)

  • No retry middleware yet — plug your own via tmsx.WithTransport(yourRoundTripper) for now.
  • Pagination is manual (Page + PageSize in QueryBookingsRequest); idiomatic iterator helpers later.
  • Response sub-trees with many optional fields ship as json.RawMessage to avoid bloat — unmarshal yourself for deep typing. Full typed structs come once we exercise them via the test harness.

About

Go SDK for the Tourmind TMSX hotel API

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages