{"id":37169056,"url":"https://github.com/necroin/golibs","last_synced_at":"2026-01-14T19:58:00.921Z","repository":{"id":191747929,"uuid":"685153014","full_name":"necroin/golibs","owner":"necroin","description":"Package of useful golang libraries","archived":false,"fork":false,"pushed_at":"2025-12-03T13:45:16.000Z","size":268,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-06T17:56:20.555Z","etag":null,"topics":["concurrency-library","concurrent","csv","fsm","go","golang","golang-library","metrics","parser","reflection-struct","tags","tokenizer"],"latest_commit_sha":null,"homepage":"","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/necroin.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-08-30T16:18:27.000Z","updated_at":"2025-12-03T13:45:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"a0eb0f13-7bad-4f99-aeb0-e2d9fb26e570","html_url":"https://github.com/necroin/golibs","commit_stats":null,"previous_names":["necroin/golibs"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/necroin/golibs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/necroin%2Fgolibs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/necroin%2Fgolibs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/necroin%2Fgolibs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/necroin%2Fgolibs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/necroin","download_url":"https://codeload.github.com/necroin/golibs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/necroin%2Fgolibs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28433843,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T18:57:19.464Z","status":"ssl_error","status_checked_at":"2026-01-14T18:52:48.501Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["concurrency-library","concurrent","csv","fsm","go","golang","golang-library","metrics","parser","reflection-struct","tags","tokenizer"],"created_at":"2026-01-14T19:58:00.356Z","updated_at":"2026-01-14T19:58:00.909Z","avatar_url":"https://github.com/necroin.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go Libraries\n- [CSV](#CSV) - Reads csv files uses tags.\n- [Concurrent](#Concurrent) - Provides thread-safe containers and atomic types.\n- [Metrics](#Metrics) - Provides thread-safe metrics.\n- [FSM](#FSM) - Provides finite state machine logic.\n- [Tokenizer](#Tokenizer) - Parses given text to tokens.\n- [RStruct](#RStruct) - Provides interface for custom struct.\n\n## CSV\nReads csv files uses tags.\n### Install\n```sh\ngo get github.com/necroin/golibs/libs/csv\n```\n### Load file\n1. Use \"csv\" tag in struct.\n- String read support\n```Go\ntype CommonRow struct {\n\tFirstHeaderValue  string `csv:\"Header1\"`\n\tSecondHeaderValue string `csv:\"Header2\"`\n\tThirdHeaderValue  string `csv:\"Header3\"`\n}\n```\n- Pointer support (`nil` by default)\n```Go\ntype PointerRow struct {\n\tFirstHeaderValue  *string `csv:\"Header1\"`\n\tSecondHeaderValue *string `csv:\"Header2\"`\n\tThirdHeaderValue  *string `csv:\"Header3\"`\n}\n```\n- Nested struct support\n```Go\ntype NestedRowValue struct {\n\tSecondHeaderValue string `csv:\"Header2\"`\n\tThirdHeaderValue  string `csv:\"Header3\"`\n}\n\ntype NestedRow struct {\n\tFirstHeaderValue string `csv:\"Header1\"`\n\tNestedValue      NestedRowValue\n}\n```\n- Standart types support\n```Go\ntype TypedRow struct {\n\tIntValue    int     `csv:\"Int\"`\n\tUintValue   uint    `csv:\"Uint\"`\n\tFloatValue  float64 `csv:\"Float\"`\n\tStringValue string  `csv:\"String\"`\n}\n```\n2. Unmarshal data\n```Go\ndata, err := os.ReadFile(\"data.csv\")\nif err != nil {\n\t// error handle\n}\n\nrows := []CommonRow{}\nif err := csv.UnmarshalData(data, \u0026rows); err != nil {\n\t// error handle\n}\n```\n### Save data to file\n```Go\nfile, err := os.Create(\"data.csv\")\nif err != nil {\n\t// error handle\n}\n\ndata := []CommonRow{\n\t{\n\t\tFirstHeaderValue:  \"R1V1\",\n\t\tSecondHeaderValue: \"R1V2\",\n\t\tThirdHeaderValue:  \"R1V3\",\n\t},\n\t{\n\t\tFirstHeaderValue:  \"R2V1\",\n\t\tSecondHeaderValue: \"R2V2\",\n\t\tThirdHeaderValue:  \"R2V3\",\n\t},\n\t{\n\t\tFirstHeaderValue:  \"R3V1\",\n\t\tSecondHeaderValue: \"R3V2\",\n\t\tThirdHeaderValue:  \"R3V3\",\n\t},\n}\n\nif err := csv.Marshal(file, data); err != nil {\n\t// error handle\n}\n```\n\n## Concurrent\nProvides thread-safe containers and atomic types.\n### Install\n```sh\ngo get github.com/necroin/golibs/libs/concurrent\n```\n### Types\n- `AtomicValue[T]`\n\t- Functions:\n\t\t- `NewAtomicValue[T any]() *AtomicValue[T]`\n\t- Methods:\n\t\t- `Get() T`\n\t\t- `Set(value T)`\n- `AtomicNumber[T]` \n\t- Types:\n\t\t- `float32` | `float64` \n\t\t- `int` | `int8` | `int16` | `int32` | `int64` \n\t\t- `uint` | `uint8` | `uint16` | `uint32` | `uint64`\n\t- Functions:\n\t\t- `NewAtomicNumber[T Number]() *AtomicNumber[T]`\n\t- Methods:\n\t\t- `Get() T`\n\t\t- `Set(value T)`\n\t\t- `Add(value T) T`\n\t\t- `Sub(value T) T`\n\t\t- `Inc() T`\n\t\t- `Dec() T`\n- `ConcurrentMap[K,V]`\n\t- Functions:\n\t\t- `NewConcurrentMap[K comparable, V any]() *ConcurrentMap[K, V]` - Constructs a new container.\n\t- Methods:\n\t\t- `Insert(key K, value V)` - Inserts element into the container, replace if the container already contain an element with an equivalent key.\n\t\t- `Find(key K) (V, bool)` - Finds an element with key equivalent to key.\n\t\t- `Erase(key K) (V, bool)` - Removes specified element from the container.\n\t\t- `Iterate(handler func(K, V))` - Iterates over elements of the container with specified handler.\n\t\t- `Size() int` - Returns the number of elements in the container.\n\t\t- `IsEmpty() bool` - Checks if the container has no elements.\n\t\t- `Keys() []K` - Returns slice of map keys.\n\t\t- `Values() []V` - Returns slice of map values.\n- `ConcurrentSlice[V]` and `ConcurrentSliceIterator[V]`\n\t- Functions:\n\t\t- `NewConcurrentSlice[V any]() *ConcurrentSlice[V]` - Constructs a new container.\n\t- Methods:\n\t\t- `Insert(index uint, value V) error` - Inserts element at the specified location in the container.\n\t\t- `Append(values ...V)` - Appends the given elements value to the end of the container.\n\t\t- `At(index uint) (V, error) ` - Returns the element at specified location index, with bounds checking.\n\t\t\t\t\t\t\t\t\t\t If index is not within the range of the container, an error is returned.\n\t\t- `Erase(index uint) error` - Erases the specified element from the container.\n\t\t- `Size() int` - Returns the number of elements in the container.\n\t\t- `IsEmpty() bool` - Checks if the container has no elements.\n\t\t- `Front() V` - Returns the first element in the container.\n\t\t\t\t\t\tCalling front on an empty container causes undefined behavior.\n\t\t- `Back() V` - Returns the last element in the container.\n\t\t\t\t\t   Calling back on an empty container causes undefined behavior.\n\t\t- `Begin() *ConcurrentSliceIterator[V]` - Returns an iterator to the first element of the container.\n\t\t- `End() *ConcurrentSliceIterator[V]` - Returns an iterator to the element following the last element of the container.\n\t- `ConcurrentSliceIterator[V]` Methods:\n\t\t- `Next() *ConcurrentSliceIterator[V]`\n\t\t- `Get() (V, error)`\n\t\t- `Pos() uint`\n\t\t- `Set(value V) error `\n\t\t- `Equal(other *ConcurrentSliceIterator[V]) bool`\n\n## Metrics\nProvides thread-safe metrics.\n- `Counter`\n- `Gauge`\n- `Label`\n- `Histogram`\n- `The above vectorized metrics with labels`\n### Install\n```sh\ngo get github.com/necroin/golibs/libs/metrics\n```\n### Types\n- `Counter` and `CounterVector`\n```Go\npackage main\n\nvar (\n\tcounter       = metrics.NewCounter(metrics.CounterOpts{Name: \"test_counter\", Help: \"Counter help information\"})\n\tcounterVector = metrics.NewCounterVector(\n\t\tmetrics.CounterOpts{Name: \"test_counter_vector\", Help: \"Counter vector help information\"},\n\t\t\"label1\", \"label2\",\n\t)\n)\n\nfunc main() {\n\tcounter.Inc()\n\tcounter.Add(rand.Float64())\n\tcounterVector.WithLabelValues(\"test11\", \"test12\").Inc()\n\tcounterVector.WithLabelValues(\"test11\", \"test12\").Add(rand.Float64())\n\n\tfmt.Println(counter.Get())\n\tfmt.Println(counterVector.WithLabelValues(\"test11\", \"test12\").Get())\n}\n```\n\n- `Gauge` and `GaugeVector`\n```Go\npackage main\n\nvar (\n\tgauge       = metrics.NewGauge(metrics.GaugeOpts{Name: \"test_gauge\", Help: \"Gauge help information\"})\n\tgaugeVector = metrics.NewGaugeVector(\n\t\tmetrics.GaugeOpts{Name: \"test_gauge_vector\", Help: \"Gauge vector help information\"},\n\t\t\"label1\", \"label2\",\n\t)\n)\n\nfunc main() {\n\tgauge.Set(rand.Float64())\n\tgauge.Add(rand.Float64())\n\tgauge.Sub(rand.Float64())\n\tgauge.Inc()\n\tgauge.Dec()\n\n\tgaugeVector.WithLabelValues(\"test11\", \"test12\").Set(rand.Float64())\n\tgaugeVector.WithLabelValues(\"test11\", \"test12\").Add(rand.Float64())\n\tgaugeVector.WithLabelValues(\"test11\", \"test12\").Sub(rand.Float64())\n\tgaugeVector.WithLabelValues(\"test11\", \"test12\").Inc()\n\tgaugeVector.WithLabelValues(\"test11\", \"test12\").Dec()\n\n\tfmt.Println(gauge.Get())\n\tfmt.Println(gaugeVector.WithLabelValues(\"test11\", \"test12\").Get())\n}\n```\n\n- `Label` and `LabelVector`\n```Go\nvar (\n\tlabel       = metrics.NewLabel(metrics.LabelOpts{Name: \"test_label\", Help: \"Label help information\"})\n\tlabelVector = metrics.NewLabelVector(\n\t\tmetrics.LabelOpts{Name: \"test_label_vector\", Help: \"Label vector help information\"},\n\t\t\"label1\", \"label2\",\n\t)\n)\n\nfunc main() {\n\tlabel.Set(RandomString(10))\n\tlabelVector.WithLabelValues(\"test11\", \"test12\").Set(RandomString(10))\n\n\tfmt.Println(label.Get())\n\tfmt.Println(labelVector.WithLabelValues(\"test11\", \"test12\").Get())\n}\n```\n\n- `Histogram` and `HistogramVector`\n```Go\npackage main\n\nvar (\n\thistogram = metrics.NewHistogram(metrics.HistogramOpts{\n\t\tName: \"test_histogram\", Help: \"Histogram help information\",\n\t\tBuckets: metrics.Buckets{Start: 0, Range: 10, Count: 10},\n\t})\n\thistogramVector = metrics.NewHistogramVector(\n\t\tmetrics.HistogramOpts{\n\t\t\tName: \"test_histogram_vector\", Help: \"Histogram vector help information\",\n\t\t\tBuckets: metrics.Buckets{Start: 0, Range: 10, Count: 10},\n\t\t},\n\t\t\"label1\", \"label2\",\n\t)\n)\n\nfunc main() {\n\thistogram.Observe(rand.Float64() * 100)\n\thistogramVector.WithLabelValues(\"test11\", \"test12\").Observe(rand.Float64() * 100)\n}\n```\n\n### Metrics server\n```Go\nfunc main() {\n\tregistry := metrics.NewRegistry()\n\tregistry.Register(counter)\n\tregistry.Register(counterVector)\n\tregistry.Register(gauge)\n\tregistry.Register(gaugeVector)\n\tregistry.Register(histogram)\n\tregistry.Register(histogramVector)\n\n\thttp.Handle(\"/metrics\", registry.Handler())\n\thttp.Handle(\"/metrics/json\", registry.JsonHandler())\n\thttp.ListenAndServe(\"localhost:3301\", nil)\n}\n```\n\n## FSM\nProvides finite state machine logic.\n### Install\n```sh\ngo get github.com/necroin/golibs/libs/fsm\n```\nTypes:\n- `FSM[Args]`\n\t- Functions:\n\t\t- `NewFSM[Args]` - Creates new FSM.\n\t- Methoods:\n\t\t- `AddState(action func()) *State[Args]`\n\t\t- `SetCurrentState(state *State[Args])`\n\t\t- `Handle(args Args)`\n\t\t- `Execute()`\n- `State[Args]`\n\t- Methoods:\n\t\t- `AddTransition(handler func(Args) *State[Args])`\n\n## Tokenizer\nParses given text to tokens.\n### Install\n```sh\ngo get github.com/necroin/golibs/libs/tokenizer\n```\nTypes:\n- `Tokenizer`\n\t- Functions:\n\t\t- `NewTokenizer(tokens ...*Token)` - Creates new Tokenizer.\n\t- Methoods:\n\t\t- `Find(text []byte) (*Token, error)`\n\t\t- `Parse(text []byte) ([]*Token, error)`\n\t\t- `SetIgnoreSpaces(value bool)`\n\t\t- `SetIgnoreTabs(value bool)`\n- `Token`\n\t- Functions:\n\t\t- `NewToken(name string, pattern string)` - Creates new Token.\n\t- Methoods:\n\t\t- `String() string`\n\t\t- `Name() string`\n\t\t- `Value() string`\n\t\t- `ValueInt() (int, error)`\n\n## RStruct\nProvides interface for custom struct.\n### Install\n```sh\ngo get github.com/necroin/golibs/libs/rstruct\n```\nTypes:\n- `RTField` - Describes the component of the field type.\n\t- Functions:\n\t\t- `NewRTField(name string, defaultValue any)` - Creates new Reflect Type Field.\n\t- Methoods:\n\t\t- `Name() string` - Returns the field name.\n\t\t- `Tags() map[string]string` - Returns a (name) - (value) tag table.\n\t\t- `SetTag(name string, value string) *RTField` - Sets the tag value by name.\n\t\t- `RemoveTag(name string)` - Deletes a tag by name.\n\t\t- `GetTag(name string) (string, bool)` - Gets the tag value by name.\n\t\t- `IsStruct() bool` - Checks RTStruct is RTStruct.\n\t\t- `AsStruct() *RTStruct` - Casts RTField to RTStruct.\n- `RVField` - Describes the component of the field value.\n\t- Methoods:\n\t\t- `Set(value any)` - Sets the value of the field.\n\t\t- `Get() any` - Gets the value of the field.\n\t\t- `Type() *RTField` - Returns the field type.\n\t\t- `String() string` - Returns the string view of the field.\n\t\t- `ToJson() ([]byte, error)` - Returns the json view of the field.\n\t\t- `IsNil() bool` - Checks the field for nil.\n\t\t- `Kind() reflect.Kind` - Returns the kind of field.\n\t\t- `IsPointer() bool` - Checks the field for a pointer.\n\t\t- `IsInterface() bool` - Checks the field for the interface.\n\t\t- `IsStruct() bool` - Checks the field for structure.\n\t\t- `IsSlice() bool` - Checks the field for a slice.\n\t\t- `IsMap() bool` - Checks the field for the map.\n\t\t- `AsStruct() *RVStruct` - Casts RVField to RVStruct.\n- `RTStruct` - Describes the component of the structure type.\n\t- Functions:\n\t\t- `NewStruct()` - Creates new Reflect Type Structure.\n\t- Methoods:\n\t\t- `New() *RVStruct` - Creates a new value for the structure.\n\t\t- `AddField(field *RTField) error` - Adds a new field.\n\t\t- `AddFields(fields ...*RTField) error` - Adds new fields.\n\t\t- `NumField() int` - Returns the number of fields.\n\t\t- `FieldByIndex(index int) *RTField` - Returns the field by index.\n\t\t- `FieldByName(name string) *RTField` - Returns a field by name.\n\t\t- `Extend(extendOptions ...ExtendOption) error` - Extends the structure using fields from another structure.\n\t\t- `String() string` - Returns the string view of the structure.\n\t\t- `SortedString() string` - Returns the string view of the structure with sorted fields.\n- `RVStruct` - Describes the component of the structure value.\n\t- Methoods:\n\t\t- `FieldByIndex(index int) *RVField` - Returns the field by index.\n\t\t- `FieldByName(name string) *RVField` - Returns a field by name.\n\t\t- `FieldsListByTag(tag string) []*RVField` - Returns a list of fields with the specified tag.\n\t\t- `FieldsMapByTag(tag string) map[string]*RVField` - Returns a map of fields with the specified tag, where the key is the tag value.\n\t\t- `Type() *RTStruct` - Returns the field type.\n\t\t- `String() string` - Returns the string view of the structure.\n\t\t- `ToMap(tag string) map[string]any` - Returns the (field name) - (value) table.\n\t\t- `ToJson(tag string)` - Returns the json view of the structure.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnecroin%2Fgolibs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnecroin%2Fgolibs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnecroin%2Fgolibs/lists"}