{"id":22663577,"url":"https://github.com/haimkastner/unitsnet-go","last_synced_at":"2025-09-19T00:17:46.423Z","repository":{"id":266333214,"uuid":"896889529","full_name":"haimkastner/unitsnet-go","owner":"haimkastner","description":"A better way to hold unit variables and easily convert to the destination unit","archived":false,"fork":false,"pushed_at":"2025-07-26T18:31:35.000Z","size":3029,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-26T22:59:41.636Z","etag":null,"topics":["conversion","converter","measure","measures","quantities","unit","unit-converter","units","units-of-measure"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/haimkastner/unitsnet-go","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/haimkastner.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-01T14:58:20.000Z","updated_at":"2025-07-26T18:31:38.000Z","dependencies_parsed_at":"2024-12-03T19:18:59.731Z","dependency_job_id":"58d394a3-362a-456f-b66e-39367d5f9e78","html_url":"https://github.com/haimkastner/unitsnet-go","commit_stats":null,"previous_names":["haimkastner/unitsnet-go"],"tags_count":42,"template":false,"template_full_name":null,"purl":"pkg:github/haimkastner/unitsnet-go","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haimkastner%2Funitsnet-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haimkastner%2Funitsnet-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haimkastner%2Funitsnet-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haimkastner%2Funitsnet-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haimkastner","download_url":"https://codeload.github.com/haimkastner/unitsnet-go/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haimkastner%2Funitsnet-go/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275857441,"owners_count":25541035,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-18T02:00:09.552Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["conversion","converter","measure","measures","quantities","unit","unit-converter","units","units-of-measure"],"created_at":"2024-12-09T12:21:06.121Z","updated_at":"2025-09-19T00:17:46.412Z","avatar_url":"https://github.com/haimkastner.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# unitsnet-go\n\n[![unitsnet-go](https://github.com/haimkastner/unitsnet-go/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/haimkastner/unitsnet-go/actions/workflows/build.yml)\n[![Coverage Status](https://coveralls.io/repos/github/haimkastner/unitsnet-go/badge.svg?branch=main)](https://coveralls.io/github/haimkastner/unitsnet-go?branch=main)\n [![Latest Release](https://img.shields.io/github/v/release/haimkastner/unitsnet-go)](https://github.com/haimkastner/unitsnet-go/releases)\n[![GitHub stars](https://img.shields.io/github/stars/haimkastner/unitsnet-go.svg?style=social\u0026label=Stars)](https://github.com/haimkastner/unitsnet-go/stargazers) \n[![License](https://img.shields.io/github/license/haimkastner/unitsnet-go.svg?style=social)](https://github.com/haimkastner/unitsnet-go/blob/master/LICENSE)\n[![Go Reference](https://pkg.go.dev/badge/github.com/haimkastner/unitsnet-go.svg)](https://pkg.go.dev/github.com/haimkastner/unitsnet-go)\n\nThe unitsnet-go package provides an efficient way to store unit variables and perform easy conversions to different units when it's required. \n\nIt offers support for more than 100 unit types across various unit categories, including pretty-printing, comparison, and arithmetic methods. \n\nThe API is designed to be user-friendly and straightforward to use.\n\nThe library is built on top of the [Units.NET](https://github.com/angularsen/UnitsNet) project and leverages their [definitions sources](https://github.com/angularsen/UnitsNet/tree/master/Common/UnitDefinitions) to generate the Golang units.\n\n\n###### The unitsnet-go package does not require any external dependencies or packages to function.\n\n\n[Units.NET on other platforms](#unitsnet-on-other-platforms)\n\n## Fetch package\n\n```bash \ngo get github.com/haimkastner/unitsnet-go\n```\n\n## Example Usage\n\n```golang\npackage main\n\nimport (\n    \"log\"\n    \"github.com/haimkastner/unitsnet-go/units\"\n)\n\nfunc main() {\n\n    // Create a factory instance\n    af := units.AngleFactory{}\n    \n    var angle *units.Angle\n\n    angle, _ = units.AngleFactory{}.FromDegrees(180)\n    // equals to\n    angle, _ = af.CreateAngle(180, units.AngleDegree)\n\n    log.Println(angle.Radians())      // 3.141592653589793\n    log.Println(angle.Microradians()) // 3141592.65358979\n    log.Println(angle.Gradians())     // 200\n    log.Println(angle.Microdegrees()) // 180000000\n\n    // As an alternative, a convert style method are also available\n    log.Println(angle.Convert(units.AngleRadian))      // 3.141592653589793\n    log.Println(angle.Convert(units.AngleMicroradian)) // 3141592.65358979\n    log.Println(angle.Convert(units.AngleGradian))     // 200\n    log.Println(angle.Convert(units.AngleMicrodegree)) // 180000000\n\n    // Print the default unit to_string (The default for angle is degrees)\n    log.Println(angle)  // 180.00 °\n\n    // Specify unit and fraction digits max length\n    log.Println(angle.ToString(units.AngleDegree, 0)) // 180 °\n    log.Println(angle.ToString(units.AngleRadian, 3)) // 3.141 rad\n}\n\n```\n\n## Additional methods\n\nCheck, compare, calculate etc. with unitsnet:\n\n```golang\nlf := units.LengthFactory{}\n\nlength1, _ := lf.FromMeters(10)\nlength2, _ := lf.FromDecimeters(100)\nlength3, _ := lf.FromMeters(3)\n\n// 'Equals' method\nlog.Println(length1.Equals(length2)) // true\nlog.Println(length1.Equals(length3)) // false\n\n// 'CompareTo' method\nlog.Println(length1.CompareTo(length3)) // 1;\nlog.Println(length3.CompareTo(length1)) // -1;\nlog.Println(length2.CompareTo(length1)) // 0;\n\n// Arithmetics methods\nresults1 := length1.Add(length3)\nresults2 := length1.Subtract(length3)\nresults3 := length1.Multiply(length3)\nresults4 := length1.Divide(length3)\nlog.Println(results1) // 13.00 m\nlog.Println(results2) // 7.00 m\nlog.Println(results3) // 30.00 m\nlog.Println(results4) // 3.33 m\n```\n\n\n## DTO - Data Transfer Object\n\nAs UnitsNet provides a convenient way to work within a running service, there are occasions where the data needs to be exposed outside of the service, typically through an API containing the unit value or consumed from an API.\n\nTo support this with a clear API schema and make it easy to convert to and from this schema to the specific format, it's recommended to use DTOs and the UnitsNet flavor converters.\n```golang\nlf := units.LengthFactory{}\n\nlength, _ := lf.FromMeters(100.01)\n// Obtain the DTO object as json, represented by the default unit - meter\nlengthDtoJson, _ := length.ToDtoJSON(nil)\nlog.Println(string(lengthDtoJson)) // {\"value\":100.01,\"unit\":\"Meter\"}\n\n// Obtain the same value but represent DTO in KM\nlengthKilometer := units.LengthKilometer // Default value\nlengthDtoRepresentsInKmJson, _ := length.ToDtoJSON(\u0026lengthKilometer)\nlog.Println(string(lengthDtoRepresentsInKmJson)) // {\"value\":0.10001,\"unit\":\"Kilometer\"}\n\n// Load JSON to DTO, and load\nlengthFromMetersDto, _ := lf.FromDtoJSON(lengthDtoJson)\nlog.Println(lengthFromMetersDto) // 100.01 m\n// The exact same value as\nlengthFromKmDto, _ := lf.FromDtoJSON(lengthDtoRepresentsInKmJson)\nlog.Println(lengthFromKmDto) // 100.01 m\n\n// Additionally, it supports creating and handling as a DTO instance, as well as creating and converting to/from JSON.\n\n// Get a DTO instance from a Length instance\nlengthDto := length.ToDto(nil)\n// Get the json representation of the DTO\nlengthJson, _ := lengthDto.ToJSON() // {\"value\":100.01,\"unit\":\"Meter\"}\n// Obtain DTO instance from a json representation\nlengthDtoFromJson, _ := units.LengthDtoFactory{}.FromJSON(lengthJson)\n// Obtain Length unit from a DTO instance\nlengthFromJson, _ := lf.FromDto(*lengthDtoFromJson)\nlog.Println(lengthFromJson) // 100.01 m\n```\n\nCheck out the OpenAPI [unitsnet-openapi-spec](https://haimkastner.github.io/unitsnet-openapi-spec-example/) example schema.\n\nAlso, refer to the detailed discussions on GitHub: [haimkastner/unitsnet-js#31](https://github.com/haimkastner/unitsnet-js/issues/31) \u0026 [angularsen/UnitsNet#1378](https://github.com/angularsen/UnitsNet/issues/1378).\n\n## Supported units\n\n[UnitsNet supported Units](Units.md)\n\n\n## Units.NET on other platforms\n\nGet the same strongly typed units on other platforms, based on the same [unit definitions](/Common/UnitDefinitions).\n\n| Language                   | Name        | Package                                           \t\t\t\t\t | Repository                                           | Maintainers  |\n|----------------------------|-------------|---------------------------------------------------------------------|------------------------------------------------------|--------------|\n| C#                         | UnitsNet    | [nuget](https://www.nuget.org/packages/UnitsNet/) \t\t\t\t\t | [github](https://github.com/angularsen/UnitsNet)     | @angularsen  |\n| JavaScript /\u003cbr\u003eTypeScript | unitsnet-js | [npm](https://www.npmjs.com/package/unitsnet-js)  \t\t\t\t\t | [github](https://github.com/haimkastner/unitsnet-js) | @haimkastner |\n| Python                     | unitsnet-py | [pypi](https://pypi.org/project/unitsnet-py)      \t\t\t\t\t | [github](https://github.com/haimkastner/unitsnet-py) | @haimkastner |\n| Golang                     | unitsnet-go | [pkg.go.dev](https://pkg.go.dev/github.com/haimkastner/unitsnet-go) | [github](https://github.com/haimkastner/unitsnet-go) | @haimkastner |\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaimkastner%2Funitsnet-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaimkastner%2Funitsnet-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaimkastner%2Funitsnet-go/lists"}