Go to Ruby
Recorder: the polyglot Go adapter (a generated driver per function, go build). Frameworks:
net/http, Gin, Echo, Fiber and chi routes are found by analyze.
Constructs
- Errors as values:
return 0, fmt.Errorf("bad input %q", s)->raise ArgumentError, ...(the recorder reports a returned non-nil error as a raise). Sentinel errors (var ErrNotFound = errors.New(...)) ->class NotFound < StandardError.panic->raise(RuntimeError). - Multiple returns -> an array or a small
Data.define, unless the second value is the error. - Zero values: an unset
intis0,stringis"", a nil slice marshals to JSONnullwhile an empty slice marshals to[]. Match the recorded JSON exactly. - Structs ->
Data.define/Struct; JSON tags (json:"user_id,omitempty") decide the keys and whether zero values are dropped: portomitemptywithcompact/explicit checks. - Maps: iteration order is random in Go; the recorder shows a sorted or noisy order. Sort before output wherever the original's output came from a map.
- Goroutines/channels -> sequential code, or Active Job when they were background work.
- Handlers:
w.WriteHeader(201); json.NewEncoder(w).Encode(x)->render json: x, status: :created. Ginc.JSON(200, gin.H{...})->render json: {...}.http.Error(w, msg, 400)writesmsg + "\n"as text/plain:render plain: "#{msg}\n", status: :bad_request. - database/sql, sqlx, GORM -> ActiveRecord on the same tables.
Traps
- Integer types:
int32/int64/uint8overflow and wrap; Ruby never does. Port the wrap only where a recorded case reaches it. Integer division truncates toward zero (-7 / 2 == -3): Ruby floors; use.fdiv(b).truncate.%takes the dividend's sign:remainder. - Rounding:
math.Round(-2.5) == -3(half away from zero) like Ruby'sround.math.RoundToEven->round(half: :even).fmt.Sprintf("%.2f")->format("%.2f"). - Strings are bytes:
len(s)counts bytes,s[i]is a byte,for i, r := range swalks runes. Rubylengthcounts characters: usebytesize/byteslicewhere the original uses bytes. strings.Title,strings.ToUpperare Unicode-aware like Ruby'supcase;strings.Fields->split(no argument).- Floats in JSON: Go writes
1for a float64 holding 1.0; recordings show it as an int. - time.Time marshals as RFC 3339 with nanoseconds:
iso8601(9)and trim trailing zeros like Go.