# README
Gouuid 
A golang utility to work with uuid
types.
Installation
go get github.com/ubgo/gouuid
DefaultIfEmpty(val *uuid.UUID) uuid.UUID
FuncName will return the current function's name. Check if pointer of uuid is empty then return the default 00000000-0000-0000-0000-000000000000
gouuid.DefaultIfEmpty(nil) // output: 00000000-0000-0000-0000-000000000000
uid := uuid.New()
gouuid.DefaultIfEmpty(&uid) // output: some uid b7729c88-47e9-42a7-92d3-3e6bcc585f73
ParseToDefault(val string) uuid.UUID
Parse string as uuid and return default if error
ParseToDefault("not_uid") // output: 00000000-0000-0000-0000-000000000000
uid := uuid.New().String()
result = ParseToDefault(uid) // output: some uid b7729c88-47e9-42a7-92d3-3e6bcc585f73
IndexOf(slice []uuid.UUID, val uuid.UUID) (int, bool)
Check if value exist on a given uuid slice then return the index
ids := []uuid.UUID{ParseToDefault("b7729c88-47e9-42a7-92d3-3e6bcc585f73"), ParseToDefault("83adb35a-847a-4962-8e09-8311a45dc2a2"), ParseToDefault("d9d65dfc-4643-44ab-920f-c564259fd96c")}
result, _ := IndexOf(ids, ParseToDefault("83adb35a-847a-4962-8e09-8311a45dc2a2"))
// output: 1, true
Contribute
If you would like to contribute to the project, please fork it and send us a pull request. Please add tests for any new features or bug fixes.
Stay in touch
- Author - Aman Khanakia
- Website - https://khanakia.com
License
gouuid is MIT licensed.
# Functions
Check if pointer of uuid is empty then return the default 00000000-0000-0000-0000-000000000000 Use Case: let say we have ImageID : UUID sent by user via Rest API empty (nil) but database is required soem value So we need to validate the nil value before sending it to the database insert query.
Extract Slice of []uuid.UUID from a given any slice of struct.
Find the index of UUID in a give Slice.
Convert custom types to uuid.UUID[] e.g.
Try to parse string as uuid and return default if error.
Convert Postgres array `{c4ba81a1-9e57-4e60-b811-2860136ab803,e0d6cbbb-e5b8-4f84-9f11-65b7e14e5817}` to UUID Slide uuid.UUID[].
Convert slide of UUIDs to String Slice.