kikihakiem / gkit

Gkit is a toolkit for building Go applications. It's similar to Go kit except it uses generic for type-safety.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GKit

Stands for Generic Kit. Heavily inspired by Go kit.

Why?

Because this is better:

func CreateUserEndpoint(ctx context.Context, request dto.CreateUserRequest) (dto.CreateUserResponse, error) {
	response, err := doSomething(ctx, request)
	if err != nil {
		return nil, fmt.Errorf("failed to do something: %w", err)
	}

	return response, nil
}

than this:

func CreateUserEndpoint(ctx context.Context, req interface{}) (interface{}, error) {
	request, ok := req.(dto.CreateUserRequest)
	if !ok {
		return nil, fmt.Errorf("expected CreateUserRequest struct, got %+v", req)
	}

	response, err := doSomething(ctx, request)
	if err != nil {
		return nil, fmt.Errorf("failed to do something: %w", err)
	}

	return response, nil
}

Please check the example for more examples.

About

Gkit is a toolkit for building Go applications. It's similar to Go kit except it uses generic for type-safety.


Languages

Language:Go 100.0%