Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
229 changed files
with
47,159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Gopkg.toml example | ||
# | ||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
|
||
|
||
[[constraint]] | ||
name = "github.com/go-chi/chi" | ||
version = "3.3.2" | ||
|
||
[[constraint]] | ||
branch = "master" | ||
name = "github.com/titpetric/factory" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
select * from channels where channel=:id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
select * from channels |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
set -e | ||
PROJECT=$(basename $(dirname $(readlink -f $0))) | ||
|
||
NAMES=$(ls cmd/* -d | xargs -n1 basename) | ||
for NAME in $NAMES; do | ||
OSES=${OSS:-"linux darwin windows"} | ||
ARCHS=${ARCHS:-"amd64 386"} | ||
for ARCH in $ARCHS; do | ||
for OS in $OSES; do | ||
echo $OS $ARCH $NAME | ||
docker run --rm -v $(pwd):/go/src/github.com/titpetric/$PROJECT -w /go/src/github.com/titpetric/$PROJECT -e GOOS=${OS} -e GOARCH=${ARCH} -e CGO_ENABLED=0 -e GOARM=7 titpetric/golang go build -o build/${NAME}-${OS}-${ARCH} cmd/${NAME}/*.go | ||
if [ $? -eq 0 ]; then | ||
echo OK | ||
fi | ||
if [ "$OS" == "windows" ]; then | ||
mv build/${NAME}-${OS}-${ARCH} build/${NAME}-${OS}-${ARCH}.exe | ||
fi | ||
done | ||
done | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net" | ||
"os" | ||
|
||
"io/ioutil" | ||
"net/http" | ||
|
||
"github.com/davecgh/go-spew/spew" | ||
"github.com/go-chi/chi" | ||
"github.com/titpetric/factory" | ||
"github.com/titpetric/factory/resputil" | ||
) | ||
|
||
func handleError(err error, message string) { | ||
if message == "" { | ||
message = "Error making API call" | ||
} | ||
if err != nil { | ||
log.Fatalf(message+": %v", err.Error()) | ||
} | ||
} | ||
|
||
func main() { | ||
// set up flags | ||
var ( | ||
addr = flag.String("addr", ":3000", "Listen address for HTTP server") | ||
) | ||
flag.Parse() | ||
|
||
// log to stdout not stderr | ||
log.SetOutput(os.Stdout) | ||
|
||
// set up database connection | ||
factory.Database.Add("default", "sqlapi:sqlapi@tcp(db1:3306)/sqlapi?collation=utf8mb4_general_ci") | ||
|
||
db, err := factory.Database.Get() | ||
handleError(err, "Can't connect to database") | ||
db.Profiler = &factory.Database.ProfilerStdout | ||
|
||
// listen socket for http server | ||
log.Println("Starting http server on address " + *addr) | ||
listener, err := net.Listen("tcp", *addr) | ||
handleError(err, "Can't listen on addr "+*addr) | ||
|
||
r := chi.NewRouter() | ||
r.Get("/api/{call}", func(w http.ResponseWriter, r *http.Request) { | ||
call := chi.URLParam(r, "call") | ||
if call != "" { | ||
result := make([]map[string]string, 0) | ||
|
||
err := func() error { | ||
sqlfile := fmt.Sprintf("api/%s.sql", call) | ||
query, err := ioutil.ReadFile(sqlfile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
params := make(map[string]interface{}) | ||
urlQuery := r.URL.Query() | ||
for name, param := range urlQuery { | ||
params[name] = param[0] | ||
} | ||
|
||
stmt, err := db.PrepareNamed(string(query)) | ||
if err != nil { | ||
return err | ||
} | ||
rows, err := stmt.Queryx(params) | ||
if err != nil { | ||
return err | ||
} | ||
for rows.Next() { | ||
row := make(map[string]interface{}) | ||
rowStrings := make(map[string]string) | ||
err = rows.MapScan(row) | ||
if err != nil { | ||
return err | ||
} | ||
for name, val := range row { | ||
switch tval := val.(type) { | ||
case []uint8: | ||
ba := make([]byte, len(tval)) | ||
for i, v := range tval { | ||
ba[i] = byte(v) | ||
} | ||
rowStrings[name] = string(ba) | ||
default: | ||
return fmt.Errorf("Unknown column type %s %#v", name, spew.Sdump(val)) | ||
} | ||
} | ||
result = append(result, rowStrings) | ||
} | ||
return nil | ||
}() | ||
resputil.JSON(w, err, result) | ||
return | ||
} | ||
resputil.JSON(w, "Unknown API call") | ||
}) | ||
|
||
http.Serve(listener, r) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.