GithubHelp home page GithubHelp logo

go.io's Introduction

go.io

go.io is a library that provides easy to use APIs and other Go constructs for performing CRUD operations on various persistance layers both storage and in memory.

Supported persistance layers

  1. Firestore
  2. Redis(Coming soon)
  3. MySQL(Coming soon)
  4. Postgres(Coming soon)

Examples

Firestore

  1. Call your preferred persistance layer repository factory function which will return an implementation of the Repository interface:
Repository Interface
type Repository[T any] interface {
	Save(element T) (err error)
	GetById(id any, element *T) (data *T, err error)
  ...
}
Factory function signature

func CreateRepository[T any](cxt context.Context, projectId, collectionName string) types.Repository[T]

Factory function usage

firestore.CreateRepository[Post](cxt, "hallix-blog", "Post")

Code snippet:

package postrepository

import (
	"context"

	"github.com/hallix/go.io/pkg/firebase/firestore"
	"github.com/hallix/go.io/pkg/types"
)

var postRepository types.Repository[Post]

func GetRepository(cxt context.Context) types.Repository[Post] {

	if postRepository == nil {
		postRepository, _ = firestore.CreateRepository[Post](cxt, "hallix-blog", "Post")
	}

	return postRepository
}
  1. Perform CRUD operation
Usage
postRepository = postrepository.GetRepository(cxt)
postRepository.Save(post)

Code Snippet:

package postservice

import (
	"context"

	"github.com/hallix/blog-service/internal/repository/postrepository"
	"github.com/hallix/go.io/pkg/types"
)

var postRepository types.Repository[postrepository.Post]

type service struct{}

func GetService(cxt context.Context) PostService {

	if postRepository == nil {
		postRepository = postrepository.GetRepository(cxt)
	}

	return &service{}
}

func (s service) Save(post postrepository.Post) {

	postRepository.Save(post)
}

go.io's People

Contributors

hallix avatar

Stargazers

 avatar

Watchers

 avatar

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.