Code Monkey home page Code Monkey logo

golang's Introduction

Go Reference Report card

golang

various libs or tools for Golang

GoLibs

  • expexp holds experimental packages and defines various functions useful with generics of any type.
  • slog - slog provides GlogHandler, GlogHumanHandler, NewRotateHandler and MultiHandler handlers for slog
  • webhdfs - Hadoop WebHDFS REST API client library for Golang with fs module like (asynchronous) interface.
  • Thread — Thread should be used for such as calling OS services or non-Go library functions that depend on per-thread state, as runtime.LockOSThread().
  • BurstLimiter — BurstLimiter behaves like Limiter in time, BurstLimiter controls how frequently events are allowed to happen.
    • It implements a "token bucket" of size b, initially full、empty or any size, and refilled by PutToken or PutTokenN. The difference is that time/rate.Limiterinitially full and refilled at rate r tokens per second.
    • It implements a Reorder Buffer allocated by Reserve or ReserveN into account when allowing future events and Wait or WaitN blocks until lim permits n events to happen.
  • generator — Generator behaves like Generator in python or ES6, with yield and next statements.
  • signal — Signal enhances signal.Notify with the stacktrace of cgo.
  • sql — Enhance go std sql.
    • NullDuration
      • NullDuration represents an interface that may be null. NullDuration implements the Scanner interface so it can be used as a scan destination, similar to sql.NullString.
    • NullJson
      • NullJson represents an interface that may be null. NullJson implements the Scanner interface so it can be used as a scan destination, similar to sql.NullString. Deprecate, use go-nulljson instead. For more information, see: https://pkg.go.dev/github.com/searKing/golang/tools/go-nulljson
  • ternary_search_tree — A type of trie (sometimes called a prefix tree) where nodes are arranged in a manner similar to a binary search tree, but with up to three children rather than the binary tree's limit of two.
  • mux — Mux is a generic Go library to multiplex connections based on their payload. Using mux, you can serve gRPC, SSH, HTTPS, HTTP, Go RPC, and pretty much any other protocol on the same TCP listener.
  • SniffReader — A Reader that allows sniff and read from the provided input reader. data is buffered if Sniff(true) is called. buffered data is taken first, if Sniff(false) is called.
  • multiple_prefix - Prefixes for decimal and binary multiples, Prefixes for decimal multiples , Prefixes for binary multiples.
  • flag — Enhance go std flag, such as StringSlice that is a flag.Value that accumulates strings, e.g. --flag=one --flag=two would produce []string{"one", "two"}.
  • goroutine — goroutine is a collection of apis about goroutine.
    • ID() — returns goroutine id of the goroutine that calls it.
    • Lock — represents a goroutine ID, with goroutine ID checked, that is whether GoRoutines of lock newer and check caller differ.
  • hashring — hashring provides a consistent hashing function, read more about consistent hashing on wikipedia: Consistent_hashing.
  • RotateFile — RotateFile derived from os.File, and is designed to ease administration of systems that generate large numbers of files. It allows automatic rotation, removal, and handler of files. Each file may be handled daily, weekly, monthly, strftimely, time_layoutly or when it grows too large.
    • NewFactoryFromFile — NewFactoryFromFile is an example of os.RotateFile register for logrus.
  • CacheFile - CacheFile is a package cache(Eventual consistency, behaves like sync.LRU[string, *os.File]), backed by a file system directory tree. It is safe for multiple processes on a single machine to use the same cache directory in a local file system simultaneously. They will coordinate using operating system file locks and may duplicate effort but will not corrupt the cache. It's usually used to support download cache, download if cache file not hit.
  • UnlinkOldestFiles - UnlinkOldestFiles unlink old files if DiskQuota exceeds. It's usually used for disk clean.

GoGenerateTools

  • go generate is only useful if you have tools to use it with! Here is an incomplete list of useful tools that generate code.

  • go-syncmap — Generates Go code using a package as a generic template for sync.Map.

  • go-syncpool — Generates Go code using a package as a generic template for sync.Pool.

  • go-atomicvalue — Generates Go code using a package as a generic template for atomic.Value.

  • go-option — Generates Go code using a package as a graceful option.

  • go-nulljson — Generates Go code using a package as a generic template that implements sql.Scanner and sql.Valuer.

  • go-enum — Generates Go code using a package as a generic template, which implements interface fmt.Stringer | binary | json | text | sql | yaml for enums.

  • go-import — Performs auto import of non go files.

  • go-sqlx — Generates Go code using a package as a generic template that implements sqlx.

golang's People

Contributors

dependabot[bot] avatar gtrevg avatar searking avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

golang's Issues

Errorf call has arguments but no formatting directives

It seems like this commit uncovered an issue with fmt.Errorf. The final generated code looks something like:

// ParseMYTYPEGOESHEREString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func ParseMYTYPEGOESHEREString(s string) (MYTYPEGOESHERE, error) {
	if val, ok := _MYTYPEGOESHERE_name_to_values[s]; ok {
		return val, nil
	}
	return 0, fmt.Errorf("MYTYPEGOESHERE does not belong to MYTYPEGOESHERE values", s)
}

Since a value of s is given, it seems like the target error would be:

fmt.Errorf("%s does not belong to MYTYPEGOESHERE values", s)

My guess is that this line should be updated from:

	return 0, fmt.Errorf("%[1]s does not belong to %[1]s values", s)

to

	return 0, fmt.Errorf("%%s does not belong to %[1]s values", s)

Does that seem right?

Thanks!

go get github.com/searKing/golang/tools/cmd/protoc-gen-go-tag fails since this morning

go get github.com/searKing/golang/tools/cmd/protoc-gen-go-tag: ambiguous import: found package github.com/searKing/golang/tools/cmd/protoc-gen-go-tag in multiple modules:
github.com/searKing/golang v1.0.101 (/go/pkg/mod/github.com/sear!king/[email protected]/tools/cmd/protoc-gen-go-tag)
github.com/searKing/golang/tools/cmd/protoc-gen-go-tag v0.0.0-20210105170217-17eed9a84a13 (/go/pkg/mod/github.com/sear!king/golang/tools/cmd/[email protected])

Looks like when we install your package we end up with it in two places under GOPATH (in my case /go:

/go/pkg/mod/github.com/sear!king/[email protected]/tools/cmd/protoc-gen-go-tag
/go/pkg/mod/github.com/sear!king/golang/tools/cmd/[email protected]

I am new at Go and not sure why the go get ends up with two copies of the code but that breaks the build of the protoc-gen-go-tag executable somehow.

Just noticed that this fails:
go get -u github.com/searKing/golang/tools/cmd/protoc-gen-go-tag

go get -u github.com/searKing/golang/tools/cmd/protoc-gen-go-tag
go: google.golang.org/protobuf upgrade => v1.25.0
go: github.com/golang/protobuf upgrade => v1.4.3
go: github.com/searKing/golang upgrade => v1.0.101
go get github.com/searKing/golang/tools/cmd/protoc-gen-go-tag: ambiguous import: found package github.com/searKing/golang/tools/cmd/protoc-gen-go-tag in multiple modules:
github.com/searKing/golang v1.0.101 (/.go/pkg/mod/github.com/sear!king/[email protected]/tools/cmd/protoc-gen-go-tag)
github.com/searKing/golang/tools/cmd/protoc-gen-go-tag v0.0.0-20210105170217-17eed9a84a13 (
/.go/pkg/mod/github.com/sear!king/golang/tools/cmd/[email protected])

While this works fine:

go get github.com/searKing/golang/tools/cmd/protoc-gen-go-tag

Note the missing -u .

go-syncmap generates invalid file for pointer values

Issue

Running go generate from tests

//go:generate go-syncmap -type "Nums<int, *string>"

provides such line in the generated file:

var nil = func() (val *string) { return }()

and it affects on the test execution:

$ ls
Nums{int,@string}.go nums_syncmap.go
$ go run .
panic: interface conversion: interface {} is nil, not *string

goroutine 1 [running]:
main.(*Nums).Load(0xc0001062a0, 0x7f, 0x3, 0x10000c000104201)
        /Users/user/Projects/searKing/golang/tools/cmd/go-syncmap/testdata/nums/nums_syncmap.go:25 +0xbb
main.ck(0x0, 0x10bdae0, 0xc000104200, 0xc0001061b0, 0x0, 0x7f, 0x10ce097, 0x8)
        /Users/user/Projects/searKing/golang/tools/cmd/go-syncmap/testdata/nums/Nums{int,@string}.go:44 +0x8a
main.main()
        /Users/user/Projects/searKing/golang/tools/cmd/go-syncmap/testdata/nums/Nums{int,@string}.go:40 +0x44e
exit status 2

Removing the line fixes the issue.

Used version

$ go get -u github.com/searKing/golang/tools/cmd/go-syncmap
go: golang.org/x/xerrors upgrade => v0.0.0-20200804184101-5ec99f83aff1
go: golang.org/x/tools upgrade => v0.0.0-20201102043006-b53d4cbd60a6
go: golang.org/x/mod upgrade => v0.3.0
go: github.com/searKing/golang upgrade => v0.0.82

Please help us with this issue

We really need your project :)

protoc-gen-go-tag: breaks reflection

I've successfully used protoc-gen-go-tag to update *.pb.go, but then I found it somehow breaks reflection (https://google.golang.org/grpc/reflection):

$ grpcui localhost:11102
Failed to compute set of methods to expose: Symbol not found: comp.proj.auth.AdminAuthSvc
caused by: File not found: github.com/searKing/golang/tools/cmd/protoc-gen-go-tag/tag/tag.proto

Any idea how to provide this file to make it available for reflection?

Json tag not getting generated for oneof fields

This is for protoc-gen-go-tag plugin
Json tags are not getting generated for proto messages which have oneof field associated in them.

message SampleRequest {

    string myName = 3 [(google.protobuf.field_tag) = {struct_tag: "json:\"my_name\""}];

    oneof input_oneof {

        string yourName = 4 [(google.protobuf.field_tag) = {struct_tag: "json:\"your_name\""}];

    }

}

The output messages from *.pb.go file looks like below:

....

type SampleRequest struct {

	state         protoimpl.MessageState

	sizeCache     protoimpl.SizeCache

	unknownFields protoimpl.UnknownFields


	MyName string `protobuf:"bytes,3,opt,name=myName,proto3" json:"my_name,omitempty"`

	// Types that are assignable to InputOneof:

	//

	//	*SampleRequest_YourName

	InputOneof isSampleRequest_InputOneof `protobuf_oneof:"input_oneof"`

}

..

..

type isSampleRequest_InputOneof interface {

	isSampleRequest_InputOneof()

}


type SampleRequest_YourName struct {

	YourName string `protobuf:"bytes,4,opt,name=yourName,proto3,oneof"`

}
.....

The json tag is mentioned for yourName field but it is missing from struct. I tried to fix/figure this out, but not able to.
Am I doing something wrong ?
I am using [email protected] and proto3.

go install invokes Replace Directives error.

I am getting the 'replace directives' error when attempting to install the tools/go-enum module:

$ go install github.com/searKing/golang/tools/go-enum@latest
go: github.com/searKing/golang/tools/[email protected] (in github.com/searKing/golang/tools/[email protected]):
	The go.mod file for the module providing named packages contains one or
	more replace directives. It must not contain directives that would cause
	it to be interpreted differently than if it were the main module.

$  go version
go version go1.21.4 darwin/arm64
$ date
Tue Jan  2 23:57:40 UTC 2024

Running on MacOS 13.6.2 (22G320).

Tags sorting is constantly changing

hi, I found a problem where re-generating *.proto files causes the tags added through your module to be overwritten in chaotic sorting. The problem is that after reflection, the tags are sorted into a map; after they are rendered into a file, the tag values are overwritten without taking into account sorting.

The problem is critical and litters commits.

image

slog & documentation

  • Do you have any beginners documentation or some example how to use your package.

  • I'm trying NewRotateTextHandler but can not find how configure RotateOption

  • and what is path, relative or absolute

  • basic try it throws error(using go version go1.21.6 windows/amd64)

# github.com/searKing/golang/go/os
..\..\..\..\go\pkg\mod\github.com\sear!king\golang\[email protected]\os\clean.go:122:24: cannot use avail (variable of type uint64) as int64 value in argument to quora.ExceedBytes
..\..\..\..\go\pkg\mod\github.com\sear!king\golang\[email protected]\os\clean.go:122:31: cannot use total (variable of type uint64) as int64 value in argument to quora.ExceedBytes
..\..\..\..\go\pkg\mod\github.com\sear!king\golang\[email protected]\os\clean.go:125:25: cannot use inodes - inodesFree (value of type uint64) as int64 value in argument to quora.ExceedInodes
..\..\..\..\go\pkg\mod\github.com\sear!king\golang\[email protected]\os\clean.go:125:44: cannot use inodes (variable of type uint64) as int64 value in argument to quora.ExceedInodes
..\..\..\..\go\pkg\mod\github.com\sear!king\golang\[email protected]\os\disk_windows.go:83:73: cannot use lpFreeBytesAvailable (variable of type int64) as uint64 value in return statement

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.