{"id":37131747,"url":"https://github.com/timob/toml","last_synced_at":"2026-01-14T15:16:35.553Z","repository":{"id":57552864,"uuid":"113077232","full_name":"timob/toml","owner":"timob","description":"TOML parser and encoder library for Golang","archived":false,"fork":true,"pushed_at":"2019-03-01T21:22:42.000Z","size":186,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-20T10:16:43.201Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"naoina/toml","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timob.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-04T18:07:48.000Z","updated_at":"2019-03-01T21:22:44.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/timob/toml","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/timob/toml","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timob%2Ftoml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timob%2Ftoml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timob%2Ftoml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timob%2Ftoml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timob","download_url":"https://codeload.github.com/timob/toml/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timob%2Ftoml/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28424108,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T13:30:50.153Z","status":"ssl_error","status_checked_at":"2026-01-14T13:29:08.907Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T15:16:34.776Z","updated_at":"2026-01-14T15:16:35.522Z","avatar_url":"https://github.com/timob.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TOML parser and encoder library for Golang [![Build Status](https://travis-ci.org/naoina/toml.png?branch=master)](https://travis-ci.org/naoina/toml)\n\n[TOML](https://github.com/toml-lang/toml) parser and encoder library for [Golang](http://golang.org/).\n\nThis library is compatible with TOML version [v0.4.0](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md).\n\n## Installation\n\n    go get -u github.com/naoina/toml\n\n## Usage\n\nThe following TOML save as `example.toml`.\n\n```toml\n# This is a TOML document. Boom.\n\ntitle = \"TOML Example\"\n\n[owner]\nname = \"Lance Uppercut\"\ndob = 1979-05-27T07:32:00-08:00 # First class dates? Why not?\n\n[database]\nserver = \"192.168.1.1\"\nports = [ 8001, 8001, 8002 ]\nconnection_max = 5000\nenabled = true\n\n[servers]\n\n  # You can indent as you please. Tabs or spaces. TOML don't care.\n  [servers.alpha]\n  ip = \"10.0.0.1\"\n  dc = \"eqdc10\"\n\n  [servers.beta]\n  ip = \"10.0.0.2\"\n  dc = \"eqdc10\"\n\n[clients]\ndata = [ [\"gamma\", \"delta\"], [1, 2] ]\n\n# Line breaks are OK when inside arrays\nhosts = [\n  \"alpha\",\n  \"omega\"\n]\n```\n\nThen above TOML will mapping to `tomlConfig` struct using `toml.Unmarshal`.\n\n```go\npackage main\n\nimport (\n    \"io/ioutil\"\n    \"os\"\n    \"time\"\n\n    \"github.com/naoina/toml\"\n)\n\ntype tomlConfig struct {\n    Title string\n    Owner struct {\n        Name string\n        Dob  time.Time\n    }\n    Database struct {\n        Server        string\n        Ports         []int\n        ConnectionMax uint\n        Enabled       bool\n    }\n    Servers map[string]ServerInfo\n    Clients struct {\n        Data  [][]interface{}\n        Hosts []string\n    }\n}\n\ntype ServerInfo struct {\n    IP net.IP\n    DC string\n}\n\nfunc main() {\n    f, err := os.Open(\"example.toml\")\n    if err != nil {\n        panic(err)\n    }\n    defer f.Close()\n    var config Config\n    if err := toml.NewDecoder(f).Decode(\u0026config); err != nil {\n        panic(err)\n    }\n\n    // then to use the unmarshaled config...\n    fmt.Println(\"IP of server 'alpha':\", config.Servers[\"alpha\"].IP)\n}\n```\n\n## Mappings\n\nA key and value of TOML will map to the corresponding field.\nThe fields of struct for mapping must be exported.\n\nThe rules of the mapping of key are following:\n\n#### Exact matching\n\n```toml\ntimeout_seconds = 256\n```\n\n```go\ntype Config struct {\n\tTimeout_seconds int\n}\n```\n\n#### Camelcase matching\n\n```toml\nserver_name = \"srv1\"\n```\n\n```go\ntype Config struct {\n\tServerName string\n}\n```\n\n#### Uppercase matching\n\n```toml\nip = \"10.0.0.1\"\n```\n\n```go\ntype Config struct {\n\tIP string\n}\n```\n\nSee the following examples for the value mappings.\n\n### String\n\n```toml\nval = \"string\"\n```\n\n```go\ntype Config struct {\n\tVal string\n}\n```\n\n### Integer\n\n```toml\nval = 100\n```\n\n```go\ntype Config struct {\n\tVal int\n}\n```\n\nAll types that can be used are following:\n\n* int8 (from `-128` to `127`)\n* int16 (from `-32768` to `32767`)\n* int32 (from `-2147483648` to `2147483647`)\n* int64 (from `-9223372036854775808` to `9223372036854775807`)\n* int (same as `int32` on 32bit environment, or `int64` on 64bit environment)\n* uint8 (from `0` to `255`)\n* uint16 (from `0` to `65535`)\n* uint32 (from `0` to `4294967295`)\n* uint64 (from `0` to `18446744073709551615`)\n* uint (same as `uint` on 32bit environment, or `uint64` on 64bit environment)\n\n### Float\n\n```toml\nval = 3.1415\n```\n\n```go\ntype Config struct {\n\tVal float32\n}\n```\n\nAll types that can be used are following:\n\n* float32\n* float64\n\n### Boolean\n\n```toml\nval = true\n```\n\n```go\ntype Config struct {\n\tVal bool\n}\n```\n\n### Datetime\n\n```toml\nval = 2014-09-28T21:27:39Z\n```\n\n```go\ntype Config struct {\n\tVal time.Time\n}\n```\n\n### Array\n\n```toml\nval = [\"a\", \"b\", \"c\"]\n```\n\n```go\ntype Config struct {\n\tVal []string\n}\n```\n\nAlso following examples all can be mapped:\n\n```toml\nval1 = [1, 2, 3]\nval2 = [[\"a\", \"b\"], [\"c\", \"d\"]]\nval3 = [[1, 2, 3], [\"a\", \"b\", \"c\"]]\nval4 = [[1, 2, 3], [[\"a\", \"b\"], [true, false]]]\n```\n\n```go\ntype Config struct {\n\tVal1 []int\n\tVal2 [][]string\n\tVal3 [][]interface{}\n\tVal4 [][]interface{}\n}\n```\n\n### Table\n\n```toml\n[server]\ntype = \"app\"\n\n  [server.development]\n  ip = \"10.0.0.1\"\n\n  [server.production]\n  ip = \"10.0.0.2\"\n```\n\n```go\ntype Config struct {\n\tServer map[string]Server\n}\n\ntype Server struct {\n\tIP string\n}\n```\n\nYou can also use the following struct instead of map of struct.\n\n```go\ntype Config struct {\n\tServer struct {\n\t\tDevelopment Server\n\t\tProduction Server\n\t}\n}\n\ntype Server struct {\n\tIP string\n}\n```\n\n### Array of Tables\n\n```toml\n[[fruit]]\n  name = \"apple\"\n\n  [fruit.physical]\n    color = \"red\"\n    shape = \"round\"\n\n  [[fruit.variety]]\n    name = \"red delicious\"\n\n  [[fruit.variety]]\n    name = \"granny smith\"\n\n[[fruit]]\n  name = \"banana\"\n\n  [[fruit.variety]]\n    name = \"plantain\"\n```\n\n```go\ntype Config struct {\n\tFruit []struct {\n\t\tName string\n\t\tPhysical struct {\n\t\t\tColor string\n\t\t\tShape string\n\t\t}\n\t\tVariety []struct {\n\t\t\tName string\n\t\t}\n\t}\n}\n```\n\n### Using the `encoding.TextUnmarshaler` interface\n\nPackage toml supports `encoding.TextUnmarshaler` (and `encoding.TextMarshaler`). You can\nuse it to apply custom marshaling rules for certain types. The `UnmarshalText` method is\ncalled with the value text found in the TOML input. TOML strings are passed unquoted.\n\n```toml\nduration = \"10s\"\n```\n\n```go\nimport time\n\ntype Duration time.Duration\n\n// UnmarshalText implements encoding.TextUnmarshaler\nfunc (d *Duration) UnmarshalText(data []byte) error {\n    duration, err := time.ParseDuration(string(data))\n    if err == nil {\n        *d = Duration(duration)\n    }\n    return err\n}\n\n// MarshalText implements encoding.TextMarshaler\nfunc (d Duration) MarshalText() ([]byte, error) {\n    return []byte(time.Duration(d).String()), nil\n}\n\ntype ConfigWithDuration struct {\n    Duration Duration\n}\n```\n### Using the `toml.UnmarshalerRec` interface\n\nYou can also override marshaling rules specifically for TOML using the `UnmarshalerRec`\nand `MarshalerRec` interfaces. These are useful if you want to control how structs or\narrays are handled. You can apply additional validation or set unexported struct fields.\n\nNote: `encoding.TextUnmarshaler` and `encoding.TextMarshaler` should be preferred for\nsimple (scalar) values because they're also compatible with other formats like JSON or\nYAML.\n\n[See the UnmarshalerRec example](https://godoc.org/github.com/naoina/toml/#example_UnmarshalerRec).\n\n### Using the `toml.Unmarshaler` interface\n\nIf you want to deal with raw TOML syntax, use the `Unmarshaler` and `Marshaler`\ninterfaces. Their input and output is raw TOML syntax. As such, these interfaces are\nuseful if you want to handle TOML at the syntax level.\n\n[See the Unmarshaler example](https://godoc.org/github.com/naoina/toml/#example_Unmarshaler).\n\n## API documentation\n\nSee [Godoc](http://godoc.org/github.com/naoina/toml).\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimob%2Ftoml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimob%2Ftoml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimob%2Ftoml/lists"}