Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Go

Generates Go structs with JSON tags.

Type Mappings

Rust TypeGo Type
Stringstring
boolbool
u8, u16, u32uint8, uint16, uint32
u64uint64
i8, i16, i32, i64int8, int16, int32, int64
f32, f64float32, float64
Uuidstring
DateTime<Utc>time.Time
Option<T>*T with omitempty
Vec<T>[]T
HashMap<K, V>map[K]V

Example

Rust:

#![allow(unused)]
fn main() {
#[derive(TypeWriter)]
#[sync_to(go)]
pub struct User {
    pub id: String,
    pub email: String,
    pub age: Option<u32>,
}
}

Generated:

package types

type User struct {
    Id    string  `json:"id"`
    Email string  `json:"email"`
    Age   *uint32 `json:"age,omitempty"`
}

Package Name

Configure the Go package name:

[go]
package_name = "models"

File Naming

Files use snake_case by default: UserProfileuser_profile.go

[go]
file_style = "PascalCase"  # UserProfile.go