dynql

package module
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2019 License: Apache-2.0 Imports: 7 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

dynql

DynQL is has one enpoint for query and tranform the Entities.

Example POST -> 127.0.0.1:9090/dql

Input:

{
    "query1": {
        "method": "demo",
        "input": {
            "name": "Pedro Martinez",
            "age": 59,
            "position": {
                "name": "manager"
            }
        },
        "output": {
            "first_name": "$.name",
            "age": "$.age",
            "level": "$.position.name"
        }
    },
    "query2": {
        "method": "demo",
        "input": {
            "name": "Marcela Perez",
            "age": 31
        }
    }
}

Output

{
    "query1": {
        "age": 59,
        "first_name": "Pedro Martinez",
        "level": "manager"
    },
    "query2": {
        "age": 31,
        "name": "Marcela Perez",
        "position": {
            "name": ""
        }
    }
}
package main

import (
	"github.com/gopher1980/dynql"
	"github.com/gorilla/mux"
	"log"
	"net/http"
)
type Position struct {
	Name string `json:"name"`
}
type Persona struct {
	Name     string   `json:"name"`
	Age      int      `json:"age"`
	Position Position `json:"position"`
}
func demo(name string, ptr interface{}, r *http.Request,payload interface{}, parent interface{}) interface{} {
	p := ptr.(*Persona)
	return p

}
func main() {
	dql := dynql.NewDQL()
	dql.Put("demo", demo, Persona{})
	r := mux.NewRouter()
	r.HandleFunc("/dql", dql.Run).Methods(http.MethodPost)
	http.Handle("/", r)
	log.Fatal(http.ListenAndServe(":9090", nil))
}

Example without strictic struct:

package main

import (
	"github.com/gopher1980/dynql"
	"github.com/gorilla/mux"
	"log"
	"net/http"
)

func demo(name string, ptr interface{}, r *http.Request,payload interface{}, parent interface{}) interface{} {
	return ptr

}
func main() {
	dql := dynql.NewDQL()
	dql.Put("demo", demo, make(map[string]interface{}))
	r := mux.NewRouter()
	r.HandleFunc("/dql", dql.Run).Methods(http.MethodPost)
	http.Handle("/", r)
	log.Fatal(http.ListenAndServe(":9090", nil))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DQL

type DQL struct {
	// contains filtered or unexported fields
}

func NewDQL

func NewDQL() *DQL

func (DQL) Get

func (dql DQL) Get(name string) Handler

func (DQL) Put

func (dql DQL) Put(name string, handler Handler, param interface{})

func (DQL) Run

func (dql DQL) Run(w http.ResponseWriter, r *http.Request)

Run execute query

type Handler

type Handler func(name string, i interface{}, r *http.Request, payload interface{}, parent interface{}) interface{}

type ParamQuery

type ParamQuery struct {
	Method string `json:"method"`
	Hidden bool
	Name   string
	Input  interface{}
	Output map[string]string
	Fork   map[string]ParamQuery
}

Jump to

Keyboard shortcuts

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