GithubHelp home page GithubHelp logo

ahsanfarooqdev / sphinx-tribes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stakwork/sphinx-tribes

0.0 0.0 0.0 1.88 GB

Backend for sphinx tribes and bounties. The bounty platform pays out in bitcoin. Sign up with Sphinx Chat, complete a bounty, and earn bitcoin! Go to our website for available bounties.

Home Page: https://community.sphinx.chat/bounties

Shell 0.08% Go 99.84% Dockerfile 0.07% Procfile 0.01%

sphinx-tribes's Introduction

Sphinx-Tribes Backend

Tribes

Sphinx-Tribes is a decentralized message broker for public groups within the Sphinx ecosystem. This README covers the setup and configuration of the Sphinx-Tribes backend.

Table of Contents

Prerequisites

  • Docker
  • Go language environment
  • PostgreSQL database
  • Redis instance (optional)
  • Relay server access (optional)

Setup

Cloning the Repository

Clone the Sphinx-Tribes repository:

git clone https://github.com/Vayras/sphinx-tribes.git

Building the Docker Image

Navigate to the cloned directory and build the Docker image:

docker build --no-cache -t sphinx-tribes .
docker tag sphinx-tribes sphinxlightning/sphinx-tribes:x
docker push sphinxlightning/sphinx-tribes:x

Environment Configuration

Create a .env file in the project root with the required environment variables.

Database Setup

Set up a PostgreSQL database and execute the provided SQL scripts to create necessary tables.

Running the Backend

Build and run the Golang backend:

go build .
./sphinx-tribes

Optional Features

Redis for Caching

Configure Redis by adding the REDIS_URL or other relevant variables to your .env file.

    RDS_HOSTNAME =
    RDS_PORT =
    RDS_DB_NAME =
    RDS_USERNAME =
    RDS_PASSWORD =

Relay Integration

For invoice creation and keysend payment, add RELAY_URL and RELAY_AUTH_KEY.

Meme Image Upload

Requires a running Relay. Enable it with MEME_URL.

SuperAdmin Dashboard Access

Add public keys to SUPER_ADMINS in your .env file.

Stakwork YouTube Integration

Add STAKWORK_KEY for YouTube video downloads.

Testing and Mocking

Unit Testing

Run unit tests with coverage:

    // you may need to install cover with this command first
    go get golang.org/x/tools/cmd/cover
    // run test
    RELAY_AUTH_KEY=TEST go test ./... -tags mock -race -v -coverprofile=coverage.out && ./cover-check.sh coverage.out <min coverage amount>
    // To get code coverage in html format do the following after running the code above
    go tool cover -html="coverage.out"

Mocking Interfaces

Use mockery for interface mocking.

Installing mockery

There are multiple options to install mockery. Use any one of the following to download.

Download the mockery binary

Use the release page link mockery releases to download the artifact for your respective device.

Using go install

If you have go already installed on your device you can use the go install command to download mockery.

go install github.com/vektra/mockery/[email protected]
Using homebrew

If you are on mac you can use homebrew to download mockery

brew install mockery
brew upgrade mockery

When adding a new function to the interface which is already mocked follow the below steps

  1. Update the corresponding interface with the function signature, for example if you are adding new function to the database structure make sure the interface file db/interface.go is updated with the function signature.
  2. run the command mockery to update the mocks.

To create mocks for a new interface make follow the steps below

  1. Add the new entry in the .mockery.yml file like this
with-expecter: true
dir: "mocks"
packages:
    github.com/stakwork/sphinx-tribes/db:
        interfaces:
            Database:
    github.com/stakwork/sphinx-tribes/*your-package-name*:
        interfaces:
            *your-interface-1*:
            *your-interface-2*:
  1. run the command mockery to update the mocks.

Backend API Data Validations

We are currently using gopkg.in/go-playground/validator.v9 for validation, to validate a struct add the validate property to it

type Organization struct {
  Name        string     `gorm:"unique;not null" json:"name" validate:"required"`
  Website     string     `json:"website" validate:"omitempty,uri"`
  Github      string     `json:"github" validate:"omitempty,uri"`
  Description string     `json:"description" validate:"omitempty,lte=200"`
}

Then handle the validation errors in the request handler

err = db.Validate.Struct(org)
if err != nil {
  w.WriteHeader(http.StatusBadRequest)
  msg := fmt.Sprintf("Error: did not pass validation test : %s", err)
  json.NewEncoder(w).Encode(msg)
  return
}

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests.

License

This project is licensed under the [LICENSE NAME] - see the LICENSE.md file for details.

sphinx-tribes's People

Contributors

elraphty avatar plell avatar evanfeenstra avatar kevkevinpal avatar vayras avatar amitpaliwal-rs avatar gouravmpk avatar kumarnayan avatar vividhpandey003 avatar tobi-bams avatar abdulwahab3181 avatar maradondt avatar ecurrencyhodler avatar marvel-ib avatar ekep-obasi avatar jeezman avatar hritikmunde avatar vishnu552 avatar cosmicpotato137 avatar aliraza556 avatar divyank-aggarwal avatar nebojsatomic avatar wright-eric avatar manyrios avatar faisaliqbal211 avatar mahtabbukhari avatar khaalid-oh avatar mirzahanan avatar rassl avatar yleight 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.