Version zu Ende April 2023
This commit is contained in:
commit
f967f4698f
23
Makefile
Normal file
23
Makefile
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Basic Go makefile
|
||||
|
||||
#CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-w -extldflags "-static"' -o Toolbox *.go
|
||||
#GOCMD=GOOS=js GOARCH=wasm go
|
||||
#GOCMD=go
|
||||
GOCMD=CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go
|
||||
GOBUILD=$(GOCMD) build
|
||||
GOCLEAN=$(GOCMD) clean
|
||||
GOTEST=$(GOCMD) test
|
||||
GOGET=$(GOCMD) get
|
||||
|
||||
all: build wasm
|
||||
|
||||
build:
|
||||
$(GOBUILD) -a -ldflags '-w -extldflags "-static"' -v -o Toolbox *.go
|
||||
dbg-build:
|
||||
$(GOBUILD) -v -gcflags=all="-N -l" -tags debug
|
||||
test:
|
||||
$(GOTEST) -v ./...
|
||||
clean:
|
||||
$(GOCLEAN)
|
||||
wasm:
|
||||
exec make -C ./goMetrix/app.wasm/ all &
|
2
build.js
Normal file
2
build.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
// put your build process in here.
|
||||
console.log("my build process");
|
314
defaults/defaults.go
Normal file
314
defaults/defaults.go
Normal file
|
@ -0,0 +1,314 @@
|
|||
/**
|
||||
= Creative Commons Lizenzvertrag =
|
||||
Diese Software ist von der archium GmbH, Gera ist lizenziert unter einer Creative Commons Namensnennung - Nicht kommerziell - Keine Bearbeitungen 4.0 International Lizenz. (http://creativecommons.org/licenses/by-nc-nd/4.0/deed.de)
|
||||
Individuelle über diese Lizenz hinausgehende Berechtigungen können Sie unter https://archium.org erhalten.
|
||||
|
||||
= Creative Commons License =
|
||||
Software by archium GmbH, Gera is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. (http://creativecommons.org/licenses/by-nc-nd/4.0/)
|
||||
Individual permissions beyond the scope of this license may be available at https://archium.org.
|
||||
**/
|
||||
|
||||
package defaults
|
||||
|
||||
import (
|
||||
// "errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
// "time"
|
||||
//
|
||||
gjs "github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
// DEF_log == 0 -> log aus
|
||||
const DEF_lognone = 0 // -> log aus
|
||||
const DEF_logerro = 1 // -> log an + fehler
|
||||
const DEF_logwarn = 2 // -> log an + warnungen
|
||||
const DEF_loginfo = 3 // -> log an + nachrichten
|
||||
const DEF_logdebg = 4 // -> log an + alles
|
||||
var DEF_log int = DEF_logerro // >0 = log an
|
||||
var DEF_alias string = ":root" // start.alias
|
||||
var DEF_apikey string = "00000000-0000-0000-0000-000000000000" // start.apikey
|
||||
var DEF_siteurl string = "http://127.0.0.1:8080" // start.siteurl
|
||||
var DEF_routeurl string = "https://planetary-data-portal.org" // start.routeurl
|
||||
var DEF_idletime float64 = 1800 // start.release (sekunden)
|
||||
var DEF_codebase string = "static" // root für verzeichnisse
|
||||
var DEF_toolboxdirs string = ";/fubagDataset;" //
|
||||
var DEF_metrixdirs string = "/fubagMetrix" // replacement for former metrixToolbox
|
||||
var DEF_wasmdirs_www string = "/wasm/"
|
||||
var DEF_wasmdirs_fs string = "static/wasm"
|
||||
|
||||
var DEF_httphost string = "127.0.0.1"
|
||||
var DEF_httpport int = 8085
|
||||
var DEF_dbhost string = "127.0.0.1"
|
||||
var DEF_dbport int = 6414
|
||||
var DEF_dbuser string = "postgres"
|
||||
var DEF_dbpassword string = "postgres"
|
||||
var DEF_dbname string = "fubagTools"
|
||||
|
||||
const DEF_dateISO = "2006-01-02"
|
||||
const DEF_timeISO = "15:04:05"
|
||||
const DEF_stampISO = "2006-01-02 15:04:05"
|
||||
|
||||
const (
|
||||
DEF_customerid = 1
|
||||
DEF_project = "archium"
|
||||
DEF_coninfo = "sslmode=disable host=%s port=%d user=%s password=%s dbname=%s sslmode=disable"
|
||||
DEF_schema = "html"
|
||||
DEF_tablecustomer = "html_customer"
|
||||
DEF_tablelayout = "html_layout"
|
||||
DEF_tablecontent = "html_content"
|
||||
DEF_fieldsiteurl = "hla_siteurl"
|
||||
DEF_fieldrouteurl = "hla_routeurl"
|
||||
DEF_fieldlayout = "hla_layout"
|
||||
DEF_fieldsource = "hla_source"
|
||||
DEF_fieldcontent = "hco_content"
|
||||
DEF_fieldalias = "hcu_aliasroot"
|
||||
DEF_fieldapikey = "hcu_apikey"
|
||||
DEF_fieldidletime = "hcu_idleseconds"
|
||||
DEF_fieldproject = "hcu_project"
|
||||
DEF_sqllayout = "SELECT hcu.*, hla.* " +
|
||||
"FROM %schema%.%tablecustomer% hcu " +
|
||||
"LEFT JOIN %schema%.%tablelayout% hla ON hla.hla_customerid = hcu.hcu_customerid " +
|
||||
"WHERE hcu.hcu_customerid = %customerid%;"
|
||||
DEF_sqlcontent = "SELECT hcu.*, hla.*, hco.* " +
|
||||
"FROM %schema%.%tablecustomer% hcu " +
|
||||
"LEFT JOIN %schema%.%tablelayout% hla ON hla.hla_customerid = hcu.hcu_customerid " +
|
||||
"LEFT JOIN %schema%.%tablecontent% hco ON hco.hco_customerid = hcu.hcu_customerid " +
|
||||
"WHERE hcu.hcu_customerid = %customerid% AND hco.hco_type = '%type%' " +
|
||||
"ORDER BY hco_layoutid ASC, hco_contentid ASC;"
|
||||
DEF_sqlproject = "SELECT hcu.* " +
|
||||
"FROM %schema%.%tablecustomer% hcu " +
|
||||
"WHERE hcu.hcu_customerid = %customerid%;"
|
||||
DEF_sqlgetjson = "SELECT html.\"GetJson\";('%json%');"
|
||||
DEF_sqlgetsvg = "SELECT * FROM html.\"GetSvg\"(%shadow%,%width%,%height%,'%matrix%','%viewbox%','%names%');"
|
||||
//
|
||||
DEF_sqlUserParam = "id,userIdentifier,lastName,firstName"
|
||||
DEF_sqlUserAdd = "SELECT html.\"AddUser\"('%id%', '%userIdentifier%', '%lastName%', '%firstName%');"
|
||||
)
|
||||
|
||||
func MenuRoot(_alias, _name string) string {
|
||||
return "{\n" + //
|
||||
"\t"success": true,\n" + //
|
||||
"\t"rows":[{\n" + //
|
||||
"\t\t"id":1,\n" + //
|
||||
"\t\t"text":"" + _name + "",\n" + // start-dataverse
|
||||
"\t\t"iconCls":"icon-package",\n" +
|
||||
"\t\t"attributes":{"level":1,"alias":"" + _alias + "","name":"" + _name + "","datasetPid":"%datasetPid%"},\n" + //
|
||||
"\t\t"children":%children%\n" + //
|
||||
"\t}]\n" + //
|
||||
"}"
|
||||
}
|
||||
|
||||
func MenuChildDataverse() string {
|
||||
return "{\n" + //
|
||||
"%tabb%"id":%id%,\n" + //
|
||||
"%tabb%"text":"%count%%title%",\n" + //
|
||||
"%icon%" + //
|
||||
"%tabb%"attributes":{"level":%level%,"type":"%type%"," + //
|
||||
""title":"%title%","alias":"%alias%","name":"%name%"},\n" + //
|
||||
"%tabb%"children":%children%\n" + //
|
||||
"%taba%}"
|
||||
}
|
||||
|
||||
func MenuChildDataset() string {
|
||||
return "{\n" +
|
||||
"%tabb%"id":%id%,\n" + //
|
||||
"%tabb%"text":"%count%%title%",\n" + //
|
||||
"%icon%" + //
|
||||
"%tabb%"attributes":{"level":%level%,"type":"%type%"," + //
|
||||
""datasetPid":"%datasetPid%","datasetId":"%datasetId%"," + //
|
||||
""title":"%title%","subject":%subjects%},\n" + //
|
||||
"%tabb%"children":%children%\n" + //
|
||||
"%taba%}"
|
||||
}
|
||||
|
||||
func MenuChildFile() string {
|
||||
return "{\n" + //
|
||||
"%tabb%"id":%id%,\n" + //
|
||||
"%tabb%"text":"%label%",\n" + //
|
||||
"%icon%" + //
|
||||
"%tabb%"attributes":{"level":%level%,"type":"%type%"},\n" + //
|
||||
"%tabb%"children":[]\n" + //
|
||||
"%taba%}"
|
||||
}
|
||||
|
||||
func MenuChildFileSimple() string {
|
||||
return "{\n" + //
|
||||
"%tabb%"text":"%label%",\n" + //
|
||||
"%icon%" + //
|
||||
"%tabb%"attributes":{"level":%level%,"type":"%type%"},\n" + //
|
||||
"%tabb%"children":[]\n" + //
|
||||
"%taba%}"
|
||||
}
|
||||
|
||||
func MenuChildUser() string {
|
||||
return "{\n" +
|
||||
"\t"id":%id%,\n" +
|
||||
"\t"text":"%name%",\n" +
|
||||
"\t"attributes":{"level":%level%,"lastname":"%lastname%","firstname":"%firstname%"}\n" +
|
||||
"}"
|
||||
}
|
||||
|
||||
func LogToggle(_logging int) int {
|
||||
oldlog := DEF_log
|
||||
//
|
||||
if _logging != 0 {
|
||||
log.SetOutput(os.Stdout)
|
||||
} else {
|
||||
log.SetOutput(ioutil.Discard)
|
||||
}
|
||||
DEF_log = _logging
|
||||
//
|
||||
return oldlog
|
||||
}
|
||||
|
||||
func LogMessage(_label, _message string, _loglevel int) {
|
||||
if _loglevel > 0 {
|
||||
if _loglevel <= DEF_log {
|
||||
// DEF_log == 1 -> log an + fehler
|
||||
// DEF_log == 2 -> log an + warnungen
|
||||
// DEF_log == 3 -> log an + nachrichten
|
||||
// DEF_log == 4 -> log an + mimimi
|
||||
if len(_label) > 0 {
|
||||
switch _loglevel {
|
||||
case 1:
|
||||
log.Printf("( ERROR ) > %v: %v \n", _label, _message)
|
||||
case 2:
|
||||
log.Printf("( WARN ) > %v: %v \n", _label, _message)
|
||||
case 3:
|
||||
log.Printf("( INFO ) > %v: %v \n", _label, _message)
|
||||
case 4:
|
||||
log.Printf("( DEBG ) > %v: %v \n", _label, _message)
|
||||
}
|
||||
} else {
|
||||
switch _loglevel {
|
||||
case 1:
|
||||
log.Printf("( ERROR ) > %v \n", _message)
|
||||
case 2:
|
||||
log.Printf("( WARN ) > %v \n", _message)
|
||||
case 3:
|
||||
log.Printf("( INFO ) > %v \n", _message)
|
||||
case 4:
|
||||
log.Printf("( DEBG ) > %v \n", _message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func LogMessage2Level(_label, _message string, _loglevel int) {
|
||||
oldlog := LogToggle(_loglevel)
|
||||
LogMessage(_label, _message, _loglevel)
|
||||
LogToggle(oldlog)
|
||||
}
|
||||
|
||||
func LogError(_label string, _error error) {
|
||||
oldlog := LogToggle(1)
|
||||
LogMessage(_label, fmt.Sprintf("%v", _error), DEF_logerro)
|
||||
LogToggle(oldlog)
|
||||
}
|
||||
|
||||
func GetArguments() {
|
||||
allArgs := os.Args[1:]
|
||||
if len(allArgs) > 0 {
|
||||
log.Println("Initialize package - Parameter..")
|
||||
//LogToggle(1)
|
||||
for i, vparam := range allArgs {
|
||||
mparam := strings.Split(vparam, ":")
|
||||
switch mparam[0] {
|
||||
case "log":
|
||||
iint, err := strconv.Atoi(mparam[1])
|
||||
if err == nil {
|
||||
LogToggle(1)
|
||||
log.Printf("\t[%v]: '%v:%v'\n", i, mparam[0], mparam[1])
|
||||
LogToggle(iint)
|
||||
continue
|
||||
}
|
||||
case "host":
|
||||
DEF_httphost = mparam[1]
|
||||
case "port":
|
||||
iint, err := strconv.Atoi(mparam[1])
|
||||
if err == nil {
|
||||
DEF_httpport = iint
|
||||
}
|
||||
case "codebase":
|
||||
DEF_codebase = mparam[1]
|
||||
case "toolboxdirs":
|
||||
DEF_toolboxdirs = mparam[1]
|
||||
case "metrixdirs":
|
||||
DEF_metrixdirs = mparam[1]
|
||||
case "dbpassword":
|
||||
DEF_dbpassword = mparam[1]
|
||||
case "dbuser":
|
||||
DEF_dbuser = mparam[1]
|
||||
case "dbname":
|
||||
DEF_dbname = mparam[1]
|
||||
case "dbhost":
|
||||
DEF_dbhost = mparam[1]
|
||||
case "dbport":
|
||||
iint, err := strconv.Atoi(mparam[1])
|
||||
if err == nil {
|
||||
DEF_dbport = iint
|
||||
}
|
||||
case "dataverse":
|
||||
DEF_alias = mparam[1]
|
||||
default:
|
||||
oldlog := LogToggle(DEF_logerro)
|
||||
LogMessage("GetArguments()", fmt.Sprintf("\t[%v]: '%v:%v' is unknown.\n", i, mparam[0], mparam[1]), DEF_logerro)
|
||||
LogToggle(oldlog)
|
||||
continue
|
||||
}
|
||||
//log.Printf("\t[%v]: '%v:%v'\n", i, mparam[0], mparam[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fehler bereitstellen (momentan 20210316)
|
||||
func get_error(_error string, _type string) string {
|
||||
json := "\t" + `"success":false,` + "\n"
|
||||
json = json + "\t" + `"msg":` + "{\n"
|
||||
status := gjs.Get(_error, "status")
|
||||
if status.String() == "ERROR" {
|
||||
message := gjs.Get(_error, "message")
|
||||
if len(message.String()) > 0 {
|
||||
json = json + "\t\t" + `"title"` + ":" + `"Error"` + ",\n"
|
||||
json = json + "\t\t" + `"msg"` + ":" + `"%message%"` + ",\n"
|
||||
json = json + "\t\t" + `"type"` + ":" + `"%type%"`
|
||||
json = strings.Replace(json, "%message%", strings.Replace(message.String(), """, "'", -1), -1)
|
||||
json = strings.Replace(json, "%type%", _type, -1)
|
||||
}
|
||||
} else {
|
||||
if status.Type == gjs.Null {
|
||||
message := fmt.Sprintf("%v", _error)
|
||||
if len(message) > 0 {
|
||||
json = json + "\t\t" + `"title"` + ":" + `"Error"` + ",\n"
|
||||
json = json + "\t\t" + `"msg"` + ":" + `"%message%"` + ",\n"
|
||||
json = json + "\t\t" + `"type"` + ":" + `"%type%"`
|
||||
json = strings.Replace(json, "%message%", strings.Replace(message, """, "'", -1), -1)
|
||||
json = strings.Replace(json, "%type%", _type, -1)
|
||||
}
|
||||
}
|
||||
}
|
||||
json = json + "\n\t}"
|
||||
//
|
||||
return json
|
||||
}
|
||||
|
||||
func GetError(_error error, _type, _label string) string {
|
||||
//
|
||||
sjson := "{\n" + get_error(fmt.Sprintf("%v:<BR><BR> %v", _label, _error), _type) + "\n}"
|
||||
//
|
||||
return sjson
|
||||
}
|
||||
|
||||
func GetErrorByString(_error, _type, _label string) string {
|
||||
//
|
||||
sjson := get_error(fmt.Sprintf("%v:<BR><BR> %v", _label, _error), _type)
|
||||
//
|
||||
return sjson
|
||||
}
|
157
goDataverse/connect/connect.go
Normal file
157
goDataverse/connect/connect.go
Normal file
|
@ -0,0 +1,157 @@
|
|||
/**
|
||||
= Creative Commons Lizenzvertrag =
|
||||
Diese Software ist von der archium GmbH, Gera ist lizenziert unter einer Creative Commons Namensnennung - Nicht kommerziell - Keine Bearbeitungen 4.0 International Lizenz. (http://creativecommons.org/licenses/by-nc-nd/4.0/deed.de)
|
||||
Individuelle über diese Lizenz hinausgehende Berechtigungen können Sie unter https://archium.org erhalten.
|
||||
|
||||
= Creative Commons License =
|
||||
Software by archium GmbH, Gera is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. (http://creativecommons.org/licenses/by-nc-nd/4.0/)
|
||||
Individual permissions beyond the scope of this license may be available at https://archium.org.
|
||||
**/
|
||||
|
||||
package connect
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
// "log"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
// "net/url"
|
||||
def "Toolbox/defaults"
|
||||
tol "Toolbox/goDataverse/tools"
|
||||
)
|
||||
|
||||
func GetRequest(url string, params, header tol.ColMap) ([]byte, error) {
|
||||
client := &http.Client{}
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
for k, v := range header {
|
||||
req.Header.Add(k, v)
|
||||
}
|
||||
query := req.URL.Query()
|
||||
for k, v := range params {
|
||||
query.Add(k, v)
|
||||
}
|
||||
|
||||
req.URL.RawQuery = query.Encode()
|
||||
def.LogMessage("GetRequest(url.encode)", url, def.DEF_logdebg)
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
def.LogError("GetRequest(do)", err)
|
||||
} else {
|
||||
defer res.Body.Close()
|
||||
b, err := ioutil.ReadAll(res.Body)
|
||||
if err == nil {
|
||||
return b, err
|
||||
}
|
||||
}
|
||||
return []byte(""), err
|
||||
}
|
||||
|
||||
func GetRequestMap(_url string, params tol.ColMapInt, header tol.ColMap) ([]byte, error) {
|
||||
client := &http.Client{}
|
||||
// _url = _url + "&fq=(title:1)"
|
||||
// _url = strings.Replace(_url, "*", `((title:2.+OR+title:Ebene))`, -1)
|
||||
def.LogMessage("GetRequestMap(map)", _url, def.DEF_logdebg)
|
||||
req, _ := http.NewRequest("GET", _url, nil)
|
||||
for k, v := range header {
|
||||
req.Header.Add(k, v)
|
||||
}
|
||||
query := req.URL.Query()
|
||||
for _, ival := range params {
|
||||
for k, v := range ival {
|
||||
def.LogMessage("GetRequestMap(values)", fmt.Sprintf("%v: %v (%v)", k, v, ival), def.DEF_logdebg)
|
||||
query.Add(k, v)
|
||||
}
|
||||
}
|
||||
//
|
||||
req.URL.RawQuery = query.Encode()
|
||||
def.LogMessage("GetRequestmap(encode)", req.URL.String(), def.DEF_logdebg)
|
||||
req.URL.RawQuery = strings.Replace(req.URL.RawQuery, "_q_=", "q=", -1)
|
||||
def.LogMessage("GetRequestMap(replac)", req.URL.String(), def.DEF_logdebg)
|
||||
res, err := client.Do(req)
|
||||
if err == nil {
|
||||
defer res.Body.Close()
|
||||
b, err := ioutil.ReadAll(res.Body)
|
||||
if err == nil {
|
||||
return b, err
|
||||
}
|
||||
}
|
||||
return []byte(""), err
|
||||
}
|
||||
|
||||
func PostRequest(url string, params, header tol.ColMap) ([]byte, error) {
|
||||
client := &http.Client{}
|
||||
postData, err := json.Marshal(params)
|
||||
def.LogMessage("PostRequest(data)", fmt.Sprintf("%v", postData), def.DEF_logdebg)
|
||||
req, _ := http.NewRequest("POST", url, bytes.NewReader(postData))
|
||||
if err == nil {
|
||||
for k, v := range header {
|
||||
req.Header.Add(k, v)
|
||||
}
|
||||
res, err := client.Do(req)
|
||||
if err == nil {
|
||||
defer res.Body.Close()
|
||||
b, err := ioutil.ReadAll(res.Body)
|
||||
if err == nil {
|
||||
return b, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return []byte(""), err
|
||||
}
|
||||
|
||||
func PostRequestB(url string, postData []byte, header tol.ColMap) ([]byte, error) {
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest("POST", url, bytes.NewReader(postData))
|
||||
if err == nil {
|
||||
for k, v := range header {
|
||||
req.Header.Add(k, v)
|
||||
}
|
||||
res, err := client.Do(req)
|
||||
if err == nil {
|
||||
defer res.Body.Close()
|
||||
b, err := ioutil.ReadAll(res.Body)
|
||||
return b, err
|
||||
}
|
||||
}
|
||||
return []byte(""), err
|
||||
}
|
||||
|
||||
func DeleteRequest(url string, header tol.ColMap) ([]byte, error) {
|
||||
client := &http.Client{}
|
||||
req, _ := http.NewRequest("DELETE", url, nil)
|
||||
|
||||
for k, v := range header {
|
||||
req.Header.Add(k, v)
|
||||
}
|
||||
def.LogMessage("DeleteRequest(url)", req.URL.String(), def.DEF_logdebg)
|
||||
res, _ := client.Do(req)
|
||||
//def.LogMessage("DeleteRequest(do)", res.Request.Header., def.DEF_logdebg)
|
||||
b, err := ioutil.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
|
||||
return b, err
|
||||
}
|
||||
|
||||
func Redirect(_w http.ResponseWriter, _r *http.Request, _url string) {
|
||||
// remove/add not default ports from _r.Host
|
||||
target := _url
|
||||
// if len(_r.URL.RawQuery) > 0 {
|
||||
// target += "?" + _r.URL.RawQuery
|
||||
// }
|
||||
log.Printf("redirect to: %s", target)
|
||||
reponse, err := http.Get(_url)
|
||||
body, err := ioutil.ReadAll(reponse.Body)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("response body", reponse.Body)
|
||||
_w.Write(body)
|
||||
log.Printf("redirect to: %s, %v, %v", target, string(body), err)
|
||||
//http.Redirect(_w, _r, target, http.StatusSeeOther)
|
||||
}
|
142
goDataverse/dataset/dataset.go
Normal file
142
goDataverse/dataset/dataset.go
Normal file
|
@ -0,0 +1,142 @@
|
|||
/**
|
||||
= Creative Commons Lizenzvertrag =
|
||||
Diese Software ist von der archium GmbH, Gera ist lizenziert unter einer Creative Commons Namensnennung - Nicht kommerziell - Keine Bearbeitungen 4.0 International Lizenz. (http://creativecommons.org/licenses/by-nc-nd/4.0/deed.de)
|
||||
Individuelle über diese Lizenz hinausgehende Berechtigungen können Sie unter https://archium.org erhalten.
|
||||
|
||||
= Creative Commons License =
|
||||
Software by archium GmbH, Gera is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. (http://creativecommons.org/licenses/by-nc-nd/4.0/)
|
||||
Individual permissions beyond the scope of this license may be available at https://archium.org.
|
||||
**/
|
||||
|
||||
package dataset
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
// "log"
|
||||
"strings"
|
||||
|
||||
def "Toolbox/defaults"
|
||||
con "Toolbox/goDataverse/connect"
|
||||
tol "Toolbox/goDataverse/tools"
|
||||
|
||||
gjs "github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func GetDatasetLastVersion(_dp tol.TDVParams, _id string) (string, error) {
|
||||
var imajor int64 = 1
|
||||
var iminor int64 = 0
|
||||
var state string = "draft"
|
||||
var url string = tol.GetSiteUrl(_dp) + "/api/datasets/" + _id + "/versions"
|
||||
res, err := con.GetRequest(url, tol.ColMap{},
|
||||
tol.ColMap{"X-Dataverse-key": tol.GetApiKey(_dp)})
|
||||
if err == nil {
|
||||
var ver = tol.GetObjectFromStr(fmt.Sprintf("%s", res))
|
||||
if ver.IsObject() {
|
||||
status := gjs.Get(ver.String(), "status")
|
||||
if status.String() == "OK" {
|
||||
lst := gjs.Get(ver.String(), "data")
|
||||
if lst.IsArray() {
|
||||
for _, entry := range lst.Array() {
|
||||
if entry.IsObject() {
|
||||
tmpstate := gjs.Get(entry.String(), "versionState")
|
||||
switch tmpstate.String() {
|
||||
case "DRAFT":
|
||||
break
|
||||
case "RELEASED":
|
||||
tmpmajor := gjs.Get(entry.String(), "versionNumber")
|
||||
if tmpmajor.Int() > imajor {
|
||||
imajor = tmpmajor.Int()
|
||||
iminor = gjs.Get(entry.String(), "versionMinorNumber").Int()
|
||||
} else {
|
||||
if tmpmajor.Int() == imajor {
|
||||
tmpminor := gjs.Get(entry.String(), "versionMinorNumber")
|
||||
if tmpminor.Int() > iminor {
|
||||
iminor = tmpminor.Int()
|
||||
}
|
||||
}
|
||||
}
|
||||
state = tmpstate.String()
|
||||
break
|
||||
//fmt.Println("GetDatasetLastVersion():", _id, imajor, iminor, state, gjs.Get(entry.String(), "id"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// auswertung: falls keine "released" version vorhanden, dann draft zurück
|
||||
var version string = ":" + state
|
||||
switch state {
|
||||
case "RELEASED":
|
||||
version = fmt.Sprintf("%v.%v", imajor, iminor)
|
||||
}
|
||||
//
|
||||
return version, err
|
||||
}
|
||||
|
||||
func GetDatasetByPersistentId(_dp tol.TDVParams, _persist, _version string) (string, error) {
|
||||
var persist string = _persist
|
||||
var version string = _version
|
||||
if len(persist) == 0 {
|
||||
persist = _dp.DP_datasetPid
|
||||
}
|
||||
var url string = tol.GetSiteUrl(_dp) + "/api/datasets/:persistentId/%versions%?persistentId=" + persist
|
||||
if len(version) > 0 {
|
||||
version = "versions/" + version + "/"
|
||||
} else {
|
||||
if len(_dp.DP_datasetVersion) > 0 {
|
||||
version = "versions/" + _dp.DP_datasetVersion + "/"
|
||||
}
|
||||
}
|
||||
url = strings.Replace(url, "%versions%", version, -1)
|
||||
def.LogMessage("GetDatasetByPersistentId(url)", url, def.DEF_logdebg)
|
||||
res, err := con.GetRequest(url, tol.ColMap{},
|
||||
tol.ColMap{"X-Dataverse-key": tol.GetApiKey(_dp)})
|
||||
//
|
||||
return (fmt.Sprintf("%s", res)), err
|
||||
}
|
||||
|
||||
func GetDatasetMetadata(_dp tol.TDVParams, _id, _version string) (string, error) {
|
||||
var version string = _version
|
||||
var url string = tol.GetSiteUrl(_dp) + "/api/datasets/" + _id + "/%versions%/metadata"
|
||||
if len(version) > 0 {
|
||||
version = "versions/" + version
|
||||
} else {
|
||||
if len(_dp.DP_datasetVersion) > 0 {
|
||||
version = "versions/" + _dp.DP_datasetVersion
|
||||
} else {
|
||||
version = "versions/1.0"
|
||||
}
|
||||
}
|
||||
url = strings.Replace(url, "%versions%", version, -1)
|
||||
def.LogMessage("GetDatasetMetadata(url)", url, def.DEF_logdebg)
|
||||
res, err := con.GetRequest(url, tol.ColMap{},
|
||||
tol.ColMap{"X-Dataverse-key": tol.GetApiKey(_dp)})
|
||||
//
|
||||
return (fmt.Sprintf("%s", res)), err
|
||||
}
|
||||
|
||||
func GetDatasetMetafield(_dp tol.TDVParams, _id string) (string, error) {
|
||||
var url string = tol.GetSiteUrl(_dp) + "/api/admin/datasetfield/" + _id
|
||||
def.LogMessage("GetDatasetMetafield(url)", url, def.DEF_logdebg)
|
||||
res, err := con.GetRequest(url, tol.ColMap{},
|
||||
tol.ColMap{"X-Dataverse-key": tol.GetApiKey(_dp)})
|
||||
//
|
||||
return (fmt.Sprintf("%s", res)), err
|
||||
}
|
||||
|
||||
func CreateDataset(_dp tol.TDVParams, _parent, _params string) (string, error) {
|
||||
res, err := con.PostRequestB(tol.GetSiteUrl(_dp)+"/api/dataverses/"+_parent+"/datasets",
|
||||
[]byte(_params), tol.ColMap{"X-Dataverse-key": tol.GetApiKey(_dp)})
|
||||
//
|
||||
return (fmt.Sprintf("%s", res)), err
|
||||
}
|
||||
|
||||
//
|
||||
func DownloadByDataset(_dp tol.TDVParams) ([]byte, error) {
|
||||
res, err := con.GetRequest(tol.GetSiteUrl(_dp)+"/api/access/dataset/:persistentId/?persistentId="+_dp.DP_datasetPid,
|
||||
tol.ColMap{}, tol.ColMap{"X-Dataverse-key": tol.GetApiKey(_dp)})
|
||||
//
|
||||
return res, err
|
||||
}
|
80
goDataverse/dataverse/dataverse.go
Normal file
80
goDataverse/dataverse/dataverse.go
Normal file
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
= Creative Commons Lizenzvertrag =
|
||||
Diese Software ist von der archium GmbH, Gera ist lizenziert unter einer Creative Commons Namensnennung - Nicht kommerziell - Keine Bearbeitungen 4.0 International Lizenz. (http://creativecommons.org/licenses/by-nc-nd/4.0/deed.de)
|
||||
Individuelle über diese Lizenz hinausgehende Berechtigungen können Sie unter https://archium.org erhalten.
|
||||
|
||||
= Creative Commons License =
|
||||
Software by archium GmbH, Gera is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. (http://creativecommons.org/licenses/by-nc-nd/4.0/)
|
||||
Individual permissions beyond the scope of this license may be available at https://archium.org.
|
||||
**/
|
||||
|
||||
package dataverse
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
//
|
||||
con "Toolbox/goDataverse/connect"
|
||||
tol "Toolbox/goDataverse/tools"
|
||||
)
|
||||
|
||||
func ListDataverses(_dp tol.TDVParams) (string, error) {
|
||||
res, err := con.GetRequest(tol.GetSiteUrl(_dp)+"/api/search?q=*&types=dataverse&per_page=1000",
|
||||
tol.ColMap{}, tol.ColMap{"X-Dataverse-key": tol.GetApiKey(_dp)})
|
||||
//
|
||||
return (fmt.Sprintf("%s", res)), err
|
||||
}
|
||||
|
||||
func ListDataverses2(server_url, api_token string) string {
|
||||
response, _ := con.GetRequest(server_url+"/api/search?q=*&types=dataverse&per_page=1000",
|
||||
tol.ColMap{}, tol.ColMap{"X-Dataverse-key": api_token})
|
||||
//
|
||||
return (fmt.Sprintf("%s", response))
|
||||
}
|
||||
|
||||
func GetContentByAlias(_dp tol.TDVParams, _alias string) (string, error) {
|
||||
res, err := con.GetRequest(tol.GetSiteUrl(_dp)+"/api/dataverses/"+_alias+"/contents",
|
||||
tol.ColMap{}, tol.ColMap{"X-Dataverse-key": tol.GetApiKey(_dp)})
|
||||
//
|
||||
return (fmt.Sprintf("%s", res)), err
|
||||
}
|
||||
|
||||
func GetDataverseByIdOrAlias(_dp tol.TDVParams, _id string) (string, error) {
|
||||
res, err := con.GetRequest(tol.GetSiteUrl(_dp)+"/api/dataverses/"+_id,
|
||||
tol.ColMap{}, tol.ColMap{"X-Dataverse-key": tol.GetApiKey(_dp)})
|
||||
//
|
||||
return (fmt.Sprintf("%s", res)), err
|
||||
}
|
||||
|
||||
func GetDataverseByIdOrAlias2(server_url, api_token, id string) string {
|
||||
response, _ := con.GetRequest(server_url+"/api/dataverses/"+id, map[string]string{}, map[string]string{"X-Dataverse-key": api_token})
|
||||
//
|
||||
return (fmt.Sprintf("%s", response))
|
||||
}
|
||||
|
||||
func GetDataverseStoragesizeById(_dp tol.TDVParams, _id string) (string, error) {
|
||||
res, err := con.GetRequest(tol.GetSiteUrl(_dp)+"/api/dataverses/"+_id+"/storagesize",
|
||||
tol.ColMap{}, tol.ColMap{"X-Dataverse-key": tol.GetApiKey(_dp)})
|
||||
//
|
||||
return (fmt.Sprintf("%s", res)), err
|
||||
}
|
||||
|
||||
func IsDataverseRoot(_dp tol.TDVParams, _alias string) (string, error) {
|
||||
res, err := con.GetRequest(tol.GetSiteUrl(_dp)+"/api/dataverses/"+_alias+"/metadatablocks/isRoot",
|
||||
tol.ColMap{}, tol.ColMap{"X-Dataverse-key": tol.GetApiKey(_dp)})
|
||||
//
|
||||
return (fmt.Sprintf("%s", res)), err
|
||||
}
|
||||
|
||||
func CreateDataverse(_dp tol.TDVParams, _parent, _params string) (string, error) {
|
||||
res, err := con.PostRequestB(tol.GetSiteUrl(_dp)+"/api/dataverses/"+_parent,
|
||||
[]byte(_params), tol.ColMap{"X-Dataverse-key": tol.GetApiKey(_dp)})
|
||||
//
|
||||
return (fmt.Sprintf("%s", res)), err
|
||||
}
|
||||
|
||||
func DeleteDataverseById(_dp tol.TDVParams, _id string) (string, error) {
|
||||
res, err := con.DeleteRequest(tol.GetSiteUrl(_dp)+"/api/dataverses/"+_id,
|
||||
tol.ColMap{"X-Dataverse-key": tol.GetApiKey(_dp)})
|
||||
//
|
||||
return (fmt.Sprintf("%s", res)), err
|
||||
}
|
48
goDataverse/files/files.go
Normal file
48
goDataverse/files/files.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
= Creative Commons Lizenzvertrag =
|
||||
Diese Software ist von der archium GmbH, Gera ist lizenziert unter einer Creative Commons Namensnennung - Nicht kommerziell - Keine Bearbeitungen 4.0 International Lizenz. (http://creativecommons.org/licenses/by-nc-nd/4.0/deed.de)
|
||||
Individuelle über diese Lizenz hinausgehende Berechtigungen können Sie unter https://archium.org erhalten.
|
||||
|
||||
= Creative Commons License =
|
||||
Software by archium GmbH, Gera is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. (http://creativecommons.org/licenses/by-nc-nd/4.0/)
|
||||
Individual permissions beyond the scope of this license may be available at https://archium.org.
|
||||
**/
|
||||
|
||||
package files
|
||||
|
||||
import (
|
||||
con "Toolbox/goDataverse/connect"
|
||||
tol "Toolbox/goDataverse/tools"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
gjs "github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func GetFilesByDatasetId(_dp tol.TDVParams, _datasetid, _version string,
|
||||
_citation gjs.Result) (string, error) {
|
||||
if len(_datasetid) == 0 {
|
||||
return "", errors.New("No datasetId found.")
|
||||
}
|
||||
var datasetid string = _datasetid
|
||||
var version string = _version
|
||||
var url string = tol.GetSiteUrl(_dp) + "/api/datasets/" + datasetid + "/%versions%/files"
|
||||
if len(version) > 0 {
|
||||
version = "versions/" + version
|
||||
} else {
|
||||
if len(_dp.DP_datasetVersion) > 0 {
|
||||
version = "versions/" + _dp.DP_datasetVersion
|
||||
} else {
|
||||
version = "versions/:latest"
|
||||
}
|
||||
}
|
||||
|
||||
url = strings.Replace(url, "%versions%", version, -1)
|
||||
|
||||
//fmt.Println("URL-files:", url)
|
||||
res, err := con.GetRequest(url, map[string]string{},
|
||||
map[string]string{"X-Dataverse-key": tol.GetApiKey(_dp)})
|
||||
//
|
||||
return (fmt.Sprintf("%s", res)), err
|
||||
}
|
BIN
goDataverse/goDataverse.debug
Normal file
BIN
goDataverse/goDataverse.debug
Normal file
Binary file not shown.
1807
goDataverse/goDataverse.go
Normal file
1807
goDataverse/goDataverse.go
Normal file
File diff suppressed because it is too large
Load Diff
76
goDataverse/search/search.go
Normal file
76
goDataverse/search/search.go
Normal file
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
= Creative Commons Lizenzvertrag =
|
||||
Diese Software ist von der archium GmbH, Gera ist lizenziert unter einer Creative Commons Namensnennung - Nicht kommerziell - Keine Bearbeitungen 4.0 International Lizenz. (http://creativecommons.org/licenses/by-nc-nd/4.0/deed.de)
|
||||
Individuelle über diese Lizenz hinausgehende Berechtigungen können Sie unter https://archium.org erhalten.
|
||||
|
||||
= Creative Commons License =
|
||||
Software by archium GmbH, Gera is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. (http://creativecommons.org/licenses/by-nc-nd/4.0/)
|
||||
Individual permissions beyond the scope of this license may be available at https://archium.org.
|
||||
**/
|
||||
|
||||
package search
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
//
|
||||
def "Toolbox/defaults"
|
||||
con "Toolbox/goDataverse/connect"
|
||||
tol "Toolbox/goDataverse/tools"
|
||||
)
|
||||
|
||||
// #############################################################################
|
||||
//
|
||||
// der parameter "_q_=xxx" wird vor der abfrage in "q=xxx" umgewandelt. hierbei
|
||||
// handelt es sich um einen workaround, der garantiert, dass die
|
||||
// parameterreihenfolge bei der übergabe an die abfrage passt.
|
||||
// aus diesem grund werden hier auch 2 durchläufe benötigt...
|
||||
//
|
||||
func SearchByParams(_dvp tol.TDVParams, _params tol.ColMapInt) (string, error) {
|
||||
var par tol.ColMapInt = make(tol.ColMapInt, 0)
|
||||
var url string = tol.GetSiteUrl(_dvp) + "/api/search?"
|
||||
// 1. durchlauf query parameter anhängen
|
||||
for _, ival := range _params {
|
||||
// log.Println("SearchByParams(param1):", ival)
|
||||
for key, val := range ival {
|
||||
if key == "_q_" {
|
||||
url = url + key + "=" + val
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
// 2. durchlauf restliche parameter anhängen
|
||||
for _, ival := range _params {
|
||||
// log.Println("SearchByParams(param2):", ival)
|
||||
for key, val := range ival {
|
||||
if key != "_q_" {
|
||||
if key != "search" {
|
||||
url = url + "&" + key + "=" + val
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// def.LogMessage("", fmt.Sprintf("GetSearchResult(%v) > url: %v", "params", url), def.DEF_loginfo)
|
||||
fmt.Printf("GetSearchResult(%v) > url: %v\n", "params", url)
|
||||
response, err := con.GetRequestMap(url, par,
|
||||
map[string]string{"X-Dataverse-key": tol.GetApiKey(_dvp)})
|
||||
//
|
||||
return (fmt.Sprintf("%s", response)), err
|
||||
}
|
||||
|
||||
func SearchSimple(_dvp tol.TDVParams, _alias string, _type string, _advanced string) (string, error) {
|
||||
var par tol.ColMapInt = make(tol.ColMapInt, 0)
|
||||
var url string = tol.GetSiteUrl(_dvp) + "/api/search?q=*%type%%alias%&per_page=1000%advanced%"
|
||||
//
|
||||
url = strings.ReplaceAll(url, "%alias%", _alias)
|
||||
url = strings.ReplaceAll(url, "%type%", _type)
|
||||
url = strings.ReplaceAll(url, "%advanced%", _advanced)
|
||||
//
|
||||
def.LogMessage("", fmt.Sprintf("GetSearchResult(%v) > url: %v", "params", url), def.DEF_logdebg)
|
||||
// log.Printf("GetSearchSimple(%v) > url: %v\n", "params", url)
|
||||
response, err := con.GetRequestMap(url, par,
|
||||
map[string]string{"X-Dataverse-key": tol.GetApiKey(_dvp)})
|
||||
//
|
||||
return (fmt.Sprintf("%s", response)), err
|
||||
}
|
281
goDataverse/svg/svg.go
Normal file
281
goDataverse/svg/svg.go
Normal file
File diff suppressed because one or more lines are too long
641
goDataverse/tools/tools.go
Normal file
641
goDataverse/tools/tools.go
Normal file
|
@ -0,0 +1,641 @@
|
|||
/**
|
||||
= Creative Commons Lizenzvertrag =
|
||||
Diese Software ist von der archium GmbH, Gera ist lizenziert unter einer Creative Commons Namensnennung - Nicht kommerziell - Keine Bearbeitungen 4.0 International Lizenz. (http://creativecommons.org/licenses/by-nc-nd/4.0/deed.de)
|
||||
Individuelle über diese Lizenz hinausgehende Berechtigungen können Sie unter https://archium.org erhalten.
|
||||
|
||||
= Creative Commons License =
|
||||
Software by archium GmbH, Gera is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. (http://creativecommons.org/licenses/by-nc-nd/4.0/)
|
||||
Individual permissions beyond the scope of this license may be available at https://archium.org.
|
||||
**/
|
||||
|
||||
package tools
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"errors"
|
||||
// "fmt"
|
||||
"html"
|
||||
"net/http"
|
||||
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
def "Toolbox/defaults"
|
||||
pog "Toolbox/postgres"
|
||||
sql "database/sql"
|
||||
|
||||
gjs "github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
type TJson []map[string]interface{}
|
||||
|
||||
type TDVParams struct {
|
||||
DP_datasetId string //
|
||||
DP_datasetPid string //
|
||||
DP_datasetVersion string //
|
||||
DP_localeCode string //
|
||||
DP_fileId string //
|
||||
DP_filePid string //
|
||||
DP_apiKey string //
|
||||
DP_siteUrl string //
|
||||
DP_alias string //
|
||||
DP_routeUrl string //
|
||||
}
|
||||
|
||||
type TFVParams struct {
|
||||
FP_suid string // generierte suid (js)
|
||||
FP_type string // 'json', 'html'..
|
||||
FP_info string // optionale info (bsp.: 'read json grid')
|
||||
FP_func string // 'getHtml', 'getValues'..
|
||||
FP_modl string // 'app.active_module' (js)
|
||||
FP_what string // 'menu', 'datagrid', 'propgrid', 'login'..
|
||||
FP_suff string // 'login'
|
||||
FP_extn string // '.txt'. '.json'..
|
||||
FP_from string // 'db', 'file', 'dataverse'..
|
||||
FP_user string //
|
||||
FP_proj string // 'projektname aus tabelle'
|
||||
FP_who string // art der daten - 'user', 'data'...
|
||||
FP_time string // übergabe zeitpunkt.
|
||||
FP_alias string // alias für dataverse grid
|
||||
FP_dois string // liste der "dois" für sicherung
|
||||
FP_rout string // umleitung beim ausloggen
|
||||
FP_refr bool // refresh der session möglich
|
||||
// für svg
|
||||
FP_shad string // svg-schatten
|
||||
FP_widt string // svg-breite
|
||||
FP_heit string // svg-höhe
|
||||
FP_matx string // svg-transfor.matrix
|
||||
FP_view string // svg-viewbox
|
||||
//
|
||||
FP_qery string // abfrage-string
|
||||
//
|
||||
FP_parm ColMapInt
|
||||
}
|
||||
|
||||
type TFileColumns struct {
|
||||
FC_sequence string
|
||||
FC_field string
|
||||
FC_title string
|
||||
FC_isvisible bool
|
||||
}
|
||||
|
||||
type TValueRow struct {
|
||||
VR_key string
|
||||
VR_value string
|
||||
}
|
||||
|
||||
type TUserEntry struct {
|
||||
UE_Done bool
|
||||
UE_IpAddress string
|
||||
UE_IpPort string
|
||||
UE_IdleTime time.Time
|
||||
UE_Released time.Time
|
||||
UE_DVParams TDVParams
|
||||
UE_FVParams TFVParams
|
||||
UE_DBConn *sql.DB
|
||||
UE_Datasets string
|
||||
}
|
||||
|
||||
type SVGMap map[string]string
|
||||
type ColMap map[string]string
|
||||
type JsnColMap map[string]interface{}
|
||||
type ColMapInt map[int]map[string]string
|
||||
type RowMap map[string]map[string]string
|
||||
type JsnMapInt map[int]map[string]interface{}
|
||||
type TUserEntries map[string]TUserEntry
|
||||
type TDatasetEntries map[string]string
|
||||
|
||||
type TDataverse JsnColMap
|
||||
|
||||
// dataverse
|
||||
var Dp TDVParams
|
||||
var Fp TFVParams
|
||||
var Ue TUserEntries
|
||||
var Ds TDatasetEntries
|
||||
|
||||
var icnt int = 0
|
||||
var Col = ""
|
||||
var Val = ""
|
||||
|
||||
var Source string = "head;menu;grid;propgrid;content;login;"
|
||||
|
||||
//
|
||||
var DataColList ColMap = make(ColMap, 0)
|
||||
var FileColList ColMap = make(ColMap, 0)
|
||||
|
||||
func CheckConnection(_fparam TFVParams) (*sql.DB, error) {
|
||||
var err error = errors.New("SUID not found.")
|
||||
if len(_fparam.FP_suid) > 0 {
|
||||
var ok bool = false
|
||||
var ue TUserEntry
|
||||
//
|
||||
ue, ok = Ue[_fparam.FP_suid]
|
||||
if ok {
|
||||
// fmt.Println("CheckConnection(entry):", _fparam.FP_suid, ue.UE_DBConn)
|
||||
if ue.UE_DBConn == nil {
|
||||
ue.UE_DBConn, err = pog.GetConnection()
|
||||
if err == nil {
|
||||
//fmt.Println("CheckConnection(created 1):", _fparam.FP_suid, ue.UE_DBConn)
|
||||
Ue[_fparam.FP_suid] = ue
|
||||
return ue.UE_DBConn, nil
|
||||
}
|
||||
} else {
|
||||
return ue.UE_DBConn, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func CloseConnection(_fparam TFVParams) error {
|
||||
// var err error = errors.New("SUID not found.")
|
||||
var ue TUserEntry = Ue[_fparam.FP_suid]
|
||||
pog.CloseConnection(ue.UE_DBConn)
|
||||
//
|
||||
return nil
|
||||
}
|
||||
|
||||
func RemoveLBR(text string, repl string) string {
|
||||
re := regexp.MustCompile(`\x{000D}\x{000A}|[\x{000A}\x{000B}\x{000C}\x{000D}\x{0085}\x{2028}\x{2029}]`)
|
||||
return re.ReplaceAllString(text, repl)
|
||||
}
|
||||
|
||||
func PrintMap(_map map[string][]string) {
|
||||
for key, value := range _map {
|
||||
for fkey, fvalue := range value {
|
||||
log.Println(key, " has ", fkey, ":", fvalue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetIP(_r *http.Request) string {
|
||||
forwarded := _r.Header.Get("X-FORWARDED-FOR")
|
||||
if forwarded != "" {
|
||||
return forwarded
|
||||
}
|
||||
return _r.RemoteAddr
|
||||
}
|
||||
|
||||
func GetApiKey(_dp TDVParams) string {
|
||||
var apikey string = def.DEF_apikey
|
||||
if len(_dp.DP_apiKey) > 0 {
|
||||
apikey = _dp.DP_apiKey
|
||||
}
|
||||
//
|
||||
return apikey
|
||||
}
|
||||
|
||||
func GetSiteUrl(_dp TDVParams) string {
|
||||
var siteurl string = def.DEF_siteurl
|
||||
if len(_dp.DP_siteUrl) > 0 {
|
||||
siteurl = _dp.DP_siteUrl
|
||||
}
|
||||
//
|
||||
return siteurl
|
||||
}
|
||||
|
||||
func GetRouteUrl(_dp TDVParams) string {
|
||||
var siteurl string = def.DEF_routeurl
|
||||
if len(_dp.DP_routeUrl) > 0 {
|
||||
siteurl = _dp.DP_routeUrl
|
||||
}
|
||||
//
|
||||
return siteurl
|
||||
}
|
||||
|
||||
// get string between (tools)
|
||||
func GetstringBetween(_string string, _start string, _end string) string {
|
||||
var str = "" + _string
|
||||
var s = strings.Index(str, _start)
|
||||
if s == -1 {
|
||||
return ""
|
||||
}
|
||||
s += len(_start)
|
||||
e := strings.Index(str, _end)
|
||||
if e == -1 {
|
||||
return ""
|
||||
}
|
||||
return str[s:e]
|
||||
}
|
||||
|
||||
func AddStrings(_sum, _val string, _sep string) string {
|
||||
if len(_sum) > 0 {
|
||||
return _sum + _sep + _val
|
||||
}
|
||||
return _val
|
||||
}
|
||||
|
||||
func UniqueStrings(_str, _sep string) string {
|
||||
m := make(map[string]bool)
|
||||
keys := make([]string, 0)
|
||||
for _, c := range strings.Split(_str, _sep) {
|
||||
if _, ok := m[c]; !ok {
|
||||
m[c] = true
|
||||
keys = append(keys, c)
|
||||
}
|
||||
}
|
||||
//
|
||||
return strings.Join(keys, _sep)
|
||||
}
|
||||
|
||||
func JsonEscape(i string) string {
|
||||
b, err := json.Marshal(i)
|
||||
if err != nil {
|
||||
def.LogError("JsonEscape()", err)
|
||||
panic(err)
|
||||
}
|
||||
s := string(b)
|
||||
//
|
||||
return s[1 : len(s)-1]
|
||||
}
|
||||
|
||||
func GetTabLevel(_level int64) string {
|
||||
var tab string = ""
|
||||
for i := 0; i < int(_level); i++ {
|
||||
tab = tab + "\t"
|
||||
}
|
||||
//
|
||||
return tab
|
||||
}
|
||||
|
||||
func GetTab10(_level int) (string, string) {
|
||||
var taba string = "\t"
|
||||
var tabb string = "\t\t"
|
||||
var level int = _level
|
||||
for {
|
||||
if level < 10 {
|
||||
break
|
||||
}
|
||||
taba = taba + "\t"
|
||||
tabb = tabb + "\t"
|
||||
level = level / 10
|
||||
}
|
||||
//
|
||||
return taba, tabb
|
||||
}
|
||||
|
||||
func GetJsonResult(_base gjs.Result, _key string) gjs.Result {
|
||||
return gjs.Get(_base.String(), _key)
|
||||
}
|
||||
|
||||
func GetJsonString(_base gjs.Result, _key string) string {
|
||||
return GetJsonResult(_base, _key).String()
|
||||
}
|
||||
|
||||
func GetJsonInt(_base gjs.Result, _key string) int64 {
|
||||
return GetJsonResult(_base, _key).Int()
|
||||
}
|
||||
|
||||
func GetObjectFromStr(_objstr string) gjs.Result {
|
||||
var resobj gjs.Result = gjs.Get(`{"data":`+_objstr+`}`, "data")
|
||||
//
|
||||
return resobj
|
||||
}
|
||||
|
||||
func DoFilterByJsonStr(_objstr gjs.Result) gjs.Result {
|
||||
if _objstr.Type == gjs.String {
|
||||
_objstr = GetObjectFromStr(string(`"` + DoFilterByStr(_objstr.String()) + `"`))
|
||||
}
|
||||
//
|
||||
return _objstr
|
||||
}
|
||||
|
||||
func DoFilterByStr(_str string) string {
|
||||
var svalue string = strings.ReplaceAll(_str, "\n", " ")
|
||||
if reflect.TypeOf(_str).Name() == "string" {
|
||||
if strings.Contains(_str, `"`) {
|
||||
evalarr := strings.Split(_str, `"`)
|
||||
if len(evalarr) > 0 {
|
||||
smarshall, err := json.Marshal(_str)
|
||||
if err != nil {
|
||||
svalue = "Wrong count of double quoted sign."
|
||||
} else {
|
||||
svalue = strings.Trim(string(smarshall), `"`)
|
||||
}
|
||||
} else {
|
||||
svalue = html.EscapeString(svalue)
|
||||
// svalue = strings.ReplaceAll(svalue, `"`, """)
|
||||
}
|
||||
}
|
||||
}
|
||||
svalue = strings.ReplaceAll(svalue, "\t", "	")
|
||||
//
|
||||
return svalue
|
||||
}
|
||||
|
||||
func JsonSearch(_json gjs.Result, _key, _value string, _level int64, _caption gjs.Result) (gjs.Result, bool) {
|
||||
if _level == 0 {
|
||||
_caption.Type = gjs.Null
|
||||
} else {
|
||||
if _caption.Type != gjs.Null {
|
||||
_caption = DoFilterByJsonStr(_caption)
|
||||
//
|
||||
return _caption, true
|
||||
}
|
||||
}
|
||||
var result bool = false
|
||||
if _json.IsObject() {
|
||||
var keysearch bool = (len(_key) > 0)
|
||||
_json.ForEach(func(jkey, jvalue gjs.Result) bool {
|
||||
if jvalue.IsArray() {
|
||||
_caption, result = JsonSearch(jvalue, _key, _value, _level+1, _caption)
|
||||
// fmt.Println(GetTabLevel(_level), "(oa)", jkey, "=", _caption)
|
||||
} else {
|
||||
if jvalue.IsObject() {
|
||||
_caption, result = JsonSearch(jvalue, _key, _value, _level+1, _caption)
|
||||
// fmt.Println(GetTabLevel(_level), "(oo)", jkey, "=", _caption)
|
||||
} else {
|
||||
// fmt.Println(GetTabLevel(_level), "(ov)", _key, _value, jkey, "=", jvalue)
|
||||
if keysearch {
|
||||
if jkey.String() == _key {
|
||||
if jvalue.String() == _value {
|
||||
_caption = gjs.Get(_json.String(), "value")
|
||||
result = (_caption.Type != gjs.Null)
|
||||
// fmt.Println(GetTabLevel(_level), "(< [", _level, "] ov >)", _key, ".", _value, "=", _caption, _value)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if jkey.String() == _value {
|
||||
_caption = jvalue
|
||||
result = (_caption.Type != gjs.Null)
|
||||
// fmt.Println(GetTabLevel(_level), "(< [", _level, "] ov >)", _key, ".", _value, "=", _caption, _value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if _caption.Type != gjs.Null {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
} else {
|
||||
if _json.IsArray() {
|
||||
for jkey, jvalue := range _json.Array() {
|
||||
jkey = jkey
|
||||
if jvalue.IsArray() {
|
||||
// log.Println(GetTabLevel(_level), "(aa)", jkey, "=")
|
||||
_caption, result = JsonSearch(jvalue, _key, _value, _level+1, _caption)
|
||||
} else {
|
||||
if jvalue.IsObject() {
|
||||
// log.Println(GetTabLevel(_level), "(ao)", jkey, "=")
|
||||
_caption, result = JsonSearch(jvalue, _key, _value, _level+1, _caption)
|
||||
} else {
|
||||
// log.Println(GetTabLevel(_level), "(av)", jkey, "=", jvalue)
|
||||
if jvalue.String() == _value {
|
||||
_caption = gjs.Get(_json.String(), "value")
|
||||
// log.Println(GetTabLevel(_level), "(< [", _level, "] av >)", _key, ".", _value, "=", _caption, _value)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if _caption.Type != gjs.Null {
|
||||
_caption = DoFilterByJsonStr(_caption)
|
||||
}
|
||||
//
|
||||
// fmt.Println(GetTabLevel(_level), "(res)", _key, _value, "=", _caption)
|
||||
return _caption, result
|
||||
}
|
||||
|
||||
func AddValues(_col, _val string, _caption, _value gjs.Result) (string, string) {
|
||||
_col = AddStrings(_col, `"`+_caption.String(), `",`)
|
||||
_val = AddStrings(_val, `"`+_caption.String()+`":"`+DoFilterByStr(_value.String())+`",`, `,`)
|
||||
//
|
||||
return _col, _val
|
||||
}
|
||||
|
||||
func AddColumnToMap(_col ColMap, _key, _value gjs.Result) ColMap {
|
||||
if len(_key.String()) > 0 {
|
||||
if _value.IsObject() {
|
||||
return _col
|
||||
}
|
||||
if len(_col) == 0 {
|
||||
_col = make(ColMap)
|
||||
}
|
||||
_value = DoFilterByJsonStr(_value)
|
||||
_col[`"`+_key.String()+`"`] = `"` + _value.String() + `"`
|
||||
}
|
||||
//
|
||||
return _col
|
||||
}
|
||||
|
||||
func AddColumnToMapAsString(_col ColMap, _key, _value string) ColMap {
|
||||
if len(_key) > 0 {
|
||||
if len(_col) == 0 {
|
||||
_col = make(ColMap)
|
||||
}
|
||||
// _col[_key] = _value
|
||||
_value = DoFilterByStr(_value)
|
||||
_col[`"`+_key+`"`] = `"` + _value + `"`
|
||||
}
|
||||
//
|
||||
return _col
|
||||
}
|
||||
|
||||
func AddValueToMap(_row RowMap, _col ColMap,
|
||||
_index, _key, _value gjs.Result, _exclude, _include string) (RowMap, ColMap) {
|
||||
if len(_key.String()) > 0 {
|
||||
if _value.IsObject() {
|
||||
// log.Println("object:", _key, ",", _value)
|
||||
_value.ForEach(func(fkey, fvalue gjs.Result) bool {
|
||||
if fkey.String() == "typeName" {
|
||||
var typevalue gjs.Result
|
||||
typevalue, _ = JsonSearch(_value, "", "value", 0, typevalue)
|
||||
// log.Println("type(1):", fvalue, ",", typevalue)
|
||||
if typevalue.IsObject() || typevalue.IsArray() {
|
||||
return true
|
||||
}
|
||||
_row, _col = AddValueToMap(_row, _col, _index, fvalue, typevalue, _exclude, _include)
|
||||
return false
|
||||
}
|
||||
// log.Println("type(2):", fkey, ",", fvalue)
|
||||
_row, _col = AddValueToMap(_row, _col, _index, fkey, fvalue, _exclude, _include)
|
||||
return true
|
||||
})
|
||||
return _row, _col
|
||||
} else {
|
||||
if _value.IsArray() {
|
||||
for _, avalue := range _value.Array() {
|
||||
// log.Println("array(3):", _key, ",", avalue)
|
||||
_row, _col = AddValueToMap(_row, _col, _index, _key, avalue, _exclude, _include)
|
||||
}
|
||||
return _row, _col
|
||||
} else {
|
||||
var typevalue gjs.Result = DoFilterByJsonStr(_value)
|
||||
// fmt.Println("AddValueToMap()", _key, ":", typevalue)
|
||||
if len(_row) == 0 {
|
||||
_row = make(RowMap)
|
||||
}
|
||||
if len(_row[`"`+_index.String()+`"`]) == 0 {
|
||||
_row[`"`+_index.String()+`"`] = make(ColMap)
|
||||
}
|
||||
_row[`"`+_index.String()+`"`][`"`+_key.String()+`"`] = `"` + typevalue.String() + `"`
|
||||
_col = AddColumnToMap(_col, _key, _key)
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
return _row, _col
|
||||
}
|
||||
|
||||
func JsonSearchSet(_json gjs.Result, _key, _val string, _level int64, _caption, _value gjs.Result) (gjs.Result, gjs.Result, bool) {
|
||||
if _level == 0 {
|
||||
_value.Type = gjs.Null
|
||||
} else {
|
||||
if _value.Type != gjs.Null {
|
||||
return _caption, _value, true
|
||||
}
|
||||
}
|
||||
|
||||
var result bool = false
|
||||
if _json.IsObject() {
|
||||
_json.ForEach(func(jkey, jvalue gjs.Result) bool {
|
||||
// log.Println(GetTabLevel(_level), "(oo)", _key, _val, jkey, jvalue)
|
||||
if jvalue.IsArray() {
|
||||
// log.Println(GetTabLevel(_level), "(oa)", _key, _val, jkey, "=", jvalue, _caption, _value)
|
||||
_caption, _value, result = JsonSearchSet(jvalue, _key, _val, _level+1, _caption, _value)
|
||||
} else {
|
||||
if jvalue.IsObject() {
|
||||
var oocaption gjs.Result
|
||||
var oovalue gjs.Result
|
||||
_caption, _value, result = JsonSearchSet(jvalue, _key, _val, _level+1, oocaption, oovalue)
|
||||
if result {
|
||||
// log.Println(GetTabLevel(_level), "(ooo)", jkey, "=", jvalue, _caption, _value)
|
||||
icnt = icnt + 1
|
||||
Col, Val = AddValues(Col, Val, _caption, _value)
|
||||
return false
|
||||
}
|
||||
// log.Println(GetTabLevel(_level), "(oo)", jkey, "=", jvalue, _caption, _value)
|
||||
} else {
|
||||
// log.Println(GetTabLevel(_level), "(ov)", _key, _val, jkey, "=", jvalue)
|
||||
if jkey.String() == _key {
|
||||
_caption = gjs.Get(_json.String(), _key)
|
||||
return true
|
||||
}
|
||||
if jkey.String() == _val {
|
||||
// log.Println(GetTabLevel(_level), "(< [", _level, "] ov >)", _key, ".", _val, "=", _caption, ".", _value)
|
||||
_value = gjs.Get(_json.String(), _val)
|
||||
icnt = icnt + 1
|
||||
Col, Val = AddValues(Col, Val, _caption, _value)
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
// log.Println(GetTabLevel(_level), "(< [", _level, "] ov >)", _key, ".", _val, "=", _caption, ".", _value)
|
||||
if _value.Type != gjs.Null {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
if _value.Type != gjs.Null {
|
||||
// log.Println("JsonSearchSet(fo):", _level, _caption, _value)
|
||||
return _caption, _value, true
|
||||
}
|
||||
} else {
|
||||
if _json.IsArray() {
|
||||
for _, jvalue := range _json.Array() {
|
||||
// log.Println(GetTabLevel(_level), "(aa)", _key, _val, jkey, "=", jvalue, _caption, _value)
|
||||
if jvalue.IsArray() {
|
||||
// log.Println(GetTabLevel(_level), "(aa)", jkey, "=")
|
||||
_caption, _value, result = JsonSearchSet(jvalue, _key, _val, _level+1, _caption, _value)
|
||||
if result {
|
||||
// log.Println(GetTabLevel(_level), "(ooo)", jkey, "=", jvalue, _caption, _value)
|
||||
icnt = icnt + 1
|
||||
Col, Val = AddValues(Col, Val, _caption, _value)
|
||||
}
|
||||
} else {
|
||||
if jvalue.IsObject() {
|
||||
jvalue.ForEach(func(jjkey, jjvalue gjs.Result) bool {
|
||||
// log.Println(GetTabLevel(_level), "(ooo)", jjkey, jjvalue)
|
||||
if jjvalue.IsObject() {
|
||||
var oocaption gjs.Result
|
||||
var oovalue gjs.Result
|
||||
oocaption, oovalue, result = JsonSearchSet(jjvalue, _key, _val, _level+1, oocaption, oovalue)
|
||||
if result {
|
||||
if oovalue.Type != gjs.Null {
|
||||
icnt = icnt + 1
|
||||
Col, Val = AddValues(Col, Val, _caption, _value)
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
} else {
|
||||
// log.Println(GetTabLevel(_level), "(av)", jkey, "=", jvalue)
|
||||
if jvalue.String() == _val {
|
||||
_value = gjs.Get(_json.String(), "value")
|
||||
icnt = icnt + 1
|
||||
Col, Val = AddValues(Col, Val, _caption, _value)
|
||||
}
|
||||
}
|
||||
}
|
||||
if _value.Type != gjs.Null {
|
||||
// log.Println("JsonSearchSet(fa):", _level, _caption, _value)
|
||||
return _caption, _value, true
|
||||
}
|
||||