distributed

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

README

Go Distributed godoc Go Report Card Apache 2.0 License

A federated community API

Overview

Build federated communities using the same API. Distributed provides a single reusable API for building multiple communities on multiple platforms. Whether its for work, social, or anything else, quickly bring up the backend API for it and spin up your own frontend experience.

Usage

Distributed is built as a single program in Go.

Server

Download and install

go get github.com/m3o/go-distributed/cmd/distributed

Run the API

distributed

Your API should be running on localhost:8080

Library

Alternatively import and use it directly

package main

import (
	"net/http"

	"github.com/m3o/go-distributed"
)

func main() {
        http.HandleFunc("/upvotePost", VoteWrapper(true, false))
        http.HandleFunc("/downvotePost", VoteWrapper(false, false))
        http.HandleFunc("/upvoteComment", VoteWrapper(true, true))
        http.HandleFunc("/downvoteComment", VoteWrapper(false, true))
        http.HandleFunc("/posts", Posts)
        http.HandleFunc("/post", NewPost)
        http.HandleFunc("/comment", NewComment)
        http.HandleFunc("/comments", Comments)
        http.HandleFunc("/login", Login)
        http.HandleFunc("/readSession", ReadSession)
	http.ListenAndServe(":8080", nil)
}

Documentation

Overview

Package distributed is for building federated communities

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Comments

func Comments(w http.ResponseWriter, req *http.Request)

func Cors

func Cors(w http.ResponseWriter, req *http.Request) bool

func Login

func Login(w http.ResponseWriter, req *http.Request)

func NewComment

func NewComment(w http.ResponseWriter, req *http.Request)

func NewPost

func NewPost(w http.ResponseWriter, req *http.Request)

func Posts

func Posts(w http.ResponseWriter, req *http.Request)

func ReadSession

func ReadSession(w http.ResponseWriter, req *http.Request)

func Run

func Run(address string)

Run the server on a given address

func VoteWrapper

func VoteWrapper(upvote bool, isComment bool) func(w http.ResponseWriter, req *http.Request)

Types

type Comment

type Comment struct {
	Content   string  `json:"content"`
	Parent    string  `json:"sub"`
	Upvotes   float32 `json:"upvotes"`
	Downvotes float32 `json:"downvotes"`
	PostId    string  `json:"postId"`
	UserName  string  `json:"usernName"`
	UserId    string  `json:"userId"`
}

type CommentRequest

type CommentRequest struct {
	Comment   Comment `json:"comment"`
	SessionID string  `json:"sessionId"`
}

type CommentsRequest

type CommentsRequest struct {
	PostId string `json:"postId"`
}

type LoginRequest

type LoginRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type Post

type Post struct {
	Id           string  `json:"id"`
	UserId       string  `json:"userId"`
	UserName     string  `json:"userName"`
	Content      string  `json:"content"`
	Created      string  `json:"created"`
	Upvotes      float32 `json:"upvotes"`
	Downvotes    float32 `json:"downvotes"`
	Score        float32 `json:"score"`
	Title        string  `json:"title"`
	Url          string  `json:"url"`
	Sub          string  `json:"sub"`
	CommentCount float32 `json:"commentCount"`
}

type PostRequest

type PostRequest struct {
	Post      Post   `json:"post"`
	SessionID string `json:"sessionId"`
}

type PostsRequest

type PostsRequest struct {
	Min   int32  `json:"min"`
	Max   int32  `json:"max"`
	Limit int32  `json:"limit"`
	Sub   string `json:"sub"`
}

type VoteRequest

type VoteRequest struct {
	Id        string `json:"id"`
	SessionID string `json:"sessionId"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL