Skip to content

Commit

Permalink
QuackPipe
Browse files Browse the repository at this point in the history
architecture cleanness for quackpipe.
  • Loading branch information
afzalabbasi committed Jul 22, 2024
1 parent 9406ffc commit 1a7a94e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
18 changes: 9 additions & 9 deletions controller/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@ import (
"quackpipe/utils"
)

func QueryOperation(flagInformation *model.CommandLineFlags, query string, r *http.Request, default_path string, default_format string, default_params string) (string, error) {
func QueryOperation(flagInformation *model.CommandLineFlags, query string, r *http.Request, defaultPath string, defaultFormat string, defaultParams string) (string, error) {
// auth to hash based temp file storage
username, password, ok := r.BasicAuth()
hashdb := ""
if ok && len(password) > 0 {
hash := sha256.Sum256([]byte(username + password))
hashdb = fmt.Sprintf("%s/%x.db", default_path, hash)
hashdb = fmt.Sprintf("%s/%x.db", defaultPath, hash)
}
// extract FORMAT from query and override the current `default_format`
cleanquery, format := utils.ExtractAndRemoveFormat(query)
cleanQuery, format := utils.ExtractAndRemoveFormat(query)
if len(format) > 0 {
query = cleanquery
default_format = format
query = cleanQuery
defaultFormat = format
}

if len(format) > 0 {
query = cleanquery
default_format = format
query = cleanQuery
defaultFormat = format
}

if len(query) == 0 {
return "", errors.New("query length is empty")
} else {
rows, duration, err := db.Quack(*flagInformation, query, false, default_params, hashdb)
rows, duration, err := db.Quack(*flagInformation, query, false, defaultParams, hashdb)
if err != nil {
return "", err
} else {

result, err := utils.ConversationOfRows(rows, default_format, duration)
result, err := utils.ConversationOfRows(rows, defaultFormat, duration)
if err != nil {
return "", err
}
Expand Down
File renamed without changes.
9 changes: 1 addition & 8 deletions route/root/root_handler.go → handler/root_handler.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package root
package handlers

import (
_ "embed"
"fmt"
"github.com/gorilla/mux"
"io"
"net/http"
"quackpipe/controller/root"
Expand All @@ -18,12 +17,6 @@ type Handler struct {
FlagInformation *model.CommandLineFlags
}

// RootHandler function for the root endpoint
func RootHandler(router *mux.Router, FlagInformation *model.CommandLineFlags) *Handler {
HandlerInfo := &Handler{FlagInformation: FlagInformation}
router.HandleFunc("/", HandlerInfo.Handlers).Methods("POST", "GET")
return HandlerInfo
}
func (u *Handler) Handlers(w http.ResponseWriter, r *http.Request) {
var bodyBytes []byte
var query string
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions route/rootRouter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package route

import (
"github.com/gorilla/mux"
handlers "quackpipe/handler"
"quackpipe/model"
)

// RootHandler function for the root endpoint
func RootHandler(router *mux.Router, FlagInformation *model.CommandLineFlags) handlers.Handler {
HandlerInfo := handlers.Handler{FlagInformation: FlagInformation}
router.HandleFunc("/", HandlerInfo.Handlers).Methods("POST", "GET")
return HandlerInfo
}
5 changes: 2 additions & 3 deletions route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package route
import (
"github.com/gorilla/mux"
"quackpipe/model"
"quackpipe/route/root"
)

func NewRouter(flagInformation *model.CommandLineFlags) *mux.Router {
router := mux.NewRouter()
// Register root module routes
root.RootHandler(router, flagInformation)
// Register module routes
RootHandler(router, flagInformation)
return router
}

0 comments on commit 1a7a94e

Please sign in to comment.