Skip to content
This repository has been archived by the owner on Nov 19, 2022. It is now read-only.

Commit

Permalink
Golang rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmota committed May 5, 2019
1 parent 0cbf9c1 commit c71ba66
Show file tree
Hide file tree
Showing 139 changed files with 903 additions and 49,063 deletions.
4 changes: 0 additions & 4 deletions .dockerignore

This file was deleted.

23 changes: 0 additions & 23 deletions .editorconfig

This file was deleted.

2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

109 changes: 0 additions & 109 deletions .gitignore

This file was deleted.

10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

Empty file removed CHANGELOG.md
Empty file.
6 changes: 0 additions & 6 deletions Dockerfile

This file was deleted.

49 changes: 0 additions & 49 deletions Makefile

This file was deleted.

Empty file modified README.md
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions packages/client/hut.txt → ascii/hut.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

( )
( )
( )
Expand Down
51 changes: 51 additions & 0 deletions cmd/streamhut/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package main

import (
"fmt"
"os"
"os/signal"
"syscall"

"github.com/streamhut/streamhut/pkg/db"
"github.com/streamhut/streamhut/pkg/db/sqlite3db"
"github.com/streamhut/streamhut/pkg/httpserver"
"github.com/streamhut/streamhut/pkg/tcpserver"
"github.com/streamhut/streamhut/pkg/wsserver"
)

func main() {
dbtype := "sqlite3"
var db db.DB
if dbtype == "sqlite3" {
db = sqlite3db.NewDB(&sqlite3db.Config{
DBPath: "./data/sqlite3.db",
})
}
ws := wsserver.NewWS(&wsserver.Config{
DB: db,
})
tcpServer := tcpserver.NewServer(&tcpserver.Config{
WS: ws,
Port: 1337,
DB: db,
})

go tcpServer.Start()

server := httpserver.NewServer(&httpserver.Config{
Port: 8080,
WS: ws,
})

var gracefulStop = make(chan os.Signal)
signal.Notify(gracefulStop, syscall.SIGTERM)
signal.Notify(gracefulStop, syscall.SIGINT)
go func() {
sig := <-gracefulStop
fmt.Printf("caught sig: %+v\nshutting down...", sig)
db.Close()
os.Exit(0)
}()

server.Start()
}
19 changes: 19 additions & 0 deletions common/byteutil/byteutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package byteutil

var arrSize = 100

// BufferWithMime ...
func BufferWithMime(buf []byte, mime string) []byte {
m := make([]byte, arrSize)
copy(m, []byte(mime))
buf = append(m, buf...)
return buf
}

// DecoupleBufferWithMime ...
func DecoupleBufferWithMime(buf []byte) ([]byte, string) {
mime := buf[:arrSize]
b := buf[arrSize:]

return b, string(mime)
}
24 changes: 24 additions & 0 deletions common/byteutil/byteutil_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package byteutil

import (
"fmt"
"testing"
)

func TestBufferWithMime(t *testing.T) {
b := []byte("hello")
m := "text/plain"
bm := BufferWithMime(b, m)

fmt.Println(string(bm))
}

func TestDecoupleBufferWithMime(t *testing.T) {
b := []byte("hello")
m := "text/plain"
bm := BufferWithMime(b, m)
buf, mime := DecoupleBufferWithMime(bm)

fmt.Println(string(buf))
fmt.Println(mime)
}
22 changes: 22 additions & 0 deletions common/stringutil/stringutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package stringutil

import (
"math/rand"
"time"
)

//var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz")

// RandStringRunes ...
func RandStringRunes(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
}
return string(b)
}

func init() {
rand.Seed(time.Now().UnixNano())
}
11 changes: 11 additions & 0 deletions common/stringutil/stringutil_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package stringutil

import (
"fmt"
"testing"
)

func TestRandStringRunes(t *testing.T) {
str := RandStringRunes(5)
fmt.Println(str)
}
11 changes: 11 additions & 0 deletions common/util/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package util

// ValidChannelName ...
func ValidChannelName(channel string) bool {
return true
}

// NormalizeChannelName ...
func NormalizeChannelName(channel string) string {
return channel
}
Binary file added data/sqlite3.db
Binary file not shown.
Binary file removed designAssets/favicon.png
Binary file not shown.
Binary file removed designAssets/favicon_alert.png
Binary file not shown.
1 change: 0 additions & 1 deletion designAssets/hut.svg

This file was deleted.

0 comments on commit c71ba66

Please sign in to comment.