Skip to content

Commit

Permalink
second round of fixes for golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
refaktor committed Aug 4, 2024
1 parent 2e97be2 commit fbeccbc
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 60 deletions.
8 changes: 4 additions & 4 deletions evaldo/builtins_bcrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func __bcrypt_hash(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2
ps.FailureFlag = true
return MakeBuiltinError(ps, "Problem in hashing.", "__bcrypt_hash")
}
return env.String{string(bytes)}
return env.NewString(string(bytes))
default:
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.StringType}, "__bcrypt_hash")
Expand All @@ -34,9 +34,9 @@ func __bcrypt_check(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2
case env.String:
err := bcrypt.CompareHashAndPassword([]byte(hash.Value), []byte(password.Value))
if err == nil {
return env.Integer{1}
return env.NewInteger(1)
} else {
return env.Integer{0}
return env.NewInteger(0)
}
default:
ps.FailureFlag = true
Expand All @@ -55,7 +55,7 @@ func __generate_token(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, ar
if _, err := rand.Read(b); err != nil {
return MakeBuiltinError(ps, "Problem reading random stream.", "__generate_token")
}
return env.String{hex.EncodeToString(b)}
return env.NewString(hex.EncodeToString(b))
default:
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.IntegerType}, "__generate_token")
Expand Down
4 changes: 2 additions & 2 deletions evaldo/builtins_bson.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func BsonToValue_Map(ps *env.ProgramState, val any, typ string, meta any, topLev
fmt.Printf("Type: %T\n", val)*/
switch rval := val.(type) {
case int64:
return *env.NewInteger(int64(rval))
return *env.NewInteger(rval)
case float32:
return *env.NewDecimal(float64(rval))
case float64:
Expand All @@ -109,7 +109,7 @@ func BsonToValue_Map(ps *env.ProgramState, val any, typ string, meta any, topLev
case bson.A:
rcols := make([]string, len(cols))
for i, rr := range cols {
rcols[i] = string(rr.(string))
rcols[i] = rr.(string)
}
spr := env.NewSpreadsheet(rcols)
//rows := make([]interface{}, len(spr.Cols))
Expand Down
12 changes: 6 additions & 6 deletions evaldo/builtins_crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var Builtins_crypto = map[string]*env.Builtin{
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch addr := arg0.(type) {
case env.Native:
return env.String{hex.EncodeToString(addr.Value.([]byte))}
return env.NewString(hex.EncodeToString(addr.Value.([]byte)))
default:
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "Go-bytes//to-string")
Expand All @@ -88,7 +88,7 @@ var Builtins_crypto = map[string]*env.Builtin{
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch addr := arg0.(type) {
case env.Native:
return env.String{hex.EncodeToString(addr.Value.(ed25519.PublicKey))}
return env.NewString(hex.EncodeToString(addr.Value.(ed25519.PublicKey)))
default:
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "Ed25519-pub-key//to-string")
Expand All @@ -102,7 +102,7 @@ var Builtins_crypto = map[string]*env.Builtin{
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch addr := arg0.(type) {
case env.Native:
return env.String{hex.EncodeToString(addr.Value.(ed25519.PrivateKey))}
return env.NewString(hex.EncodeToString(addr.Value.(ed25519.PrivateKey)))
default:
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "Ed25519-priv-key//to-string")
Expand All @@ -120,8 +120,8 @@ var Builtins_crypto = map[string]*env.Builtin{
ps.FailureFlag = true
return MakeBuiltinError(ps, "Failed to generate keys.", "ed25519-generate-keys")
}
keys[0] = *env.NewNative(ps.Idx, ed25519.PublicKey(puk), "Ed25519-pub-key")
keys[1] = *env.NewNative(ps.Idx, ed25519.PrivateKey(pvk), "Ed25519-priv-key")
keys[0] = *env.NewNative(ps.Idx, puk, "Ed25519-pub-key")
keys[1] = *env.NewNative(ps.Idx, pvk, "Ed25519-priv-key")
ser := *env.NewTSeries(keys)
return *env.NewBlock(ser)
},
Expand Down Expand Up @@ -208,7 +208,7 @@ var Builtins_crypto = map[string]*env.Builtin{
h := sha512.New()
h.Write([]byte(s.Value))
bs := h.Sum(nil)
return env.String{hex.EncodeToString(bs[:])}
return env.NewString(hex.EncodeToString(bs[:]))
default:
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.StringType}, "sha512")
Expand Down
1 change: 0 additions & 1 deletion evaldo/builtins_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ func __attach(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.O
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "gomail-message//attach")
}

}

func __addAlternative(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
Expand Down
18 changes: 6 additions & 12 deletions evaldo/builtins_html.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ type HtmlDialectNode struct {
// xwords after another or conditions mean that we dive deeper, like a block { } would be

func load_html_Dict(es *env.ProgramState, block env.Block) (env.Dict, *env.Error) {

var key string
var condition *HtmlNavigCondition
var keys []string // keys
Expand Down Expand Up @@ -153,7 +152,6 @@ func load_html_Dict(es *env.ProgramState, block env.Block) (env.Dict, *env.Error
}

func do_html(es *env.ProgramState, reader io.Reader, dmap env.Dict) env.Object {

trace8("**** DO HTML **** ")
// fmt.Println(dmap)

Expand Down Expand Up @@ -181,9 +179,7 @@ func do_html(es *env.ProgramState, reader io.Reader, dmap env.Dict) env.Object {

myloop:
for {

//fmt.Println(dmap)

// Read tokens from the XML document in a stream.
rawtoken := decoder.Next()
// Inspect the type of the token just read.
Expand Down Expand Up @@ -315,7 +311,7 @@ myloop:
// fmt.Println("IN BLOCK")
ser := es.Ser // TODO -- make helper function that "does" a block
es.Ser = node.Code.Series
EvalBlockInj(es, env.String{string(tok.Data)}, true)
EvalBlockInj(es, env.NewString(tok.Data), true)
if es.ErrorFlag {
return es.Res
}
Expand Down Expand Up @@ -359,10 +355,8 @@ myloop:
m := len(tags) - 1 // Top element
curtag = tags[m]
tags = tags[:m] // Pop

// fmt.Println(stack)
// fmt.Println(tags)

}
case html.ErrorToken:
break myloop
Expand Down Expand Up @@ -426,14 +420,14 @@ var Builtins_html = map[string]*env.Builtin{
switch n := arg1.(type) {
case env.Integer:
if int(n.Value) < len(tok.Attr) {
return env.String{tok.Attr[int(n.Value)].Val}
return env.NewString(tok.Attr[int(n.Value)].Val)
} else {
return env.Void{}
}
case env.Word:
for _, a := range tok.Attr {
if a.Key == ps.Idx.GetWord(n.Index) {
return env.String{a.Val}
return env.NewString(a.Val)
}
}
return env.Void{}
Expand All @@ -457,9 +451,9 @@ var Builtins_html = map[string]*env.Builtin{
case env.Native:
switch tok := tok1.Value.(type) {
case html.Token:
return env.String{tok.Data}
return env.NewString(tok.Data)
default:
return MakeBuiltinError(ps, "Not xml-strat element.", "rye-html-start//name?")
return MakeBuiltinError(ps, "Not xml-start element.", "rye-html-start//name?")
}
default:
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "rye-html-start//name?")
Expand All @@ -476,7 +470,7 @@ var Builtins_html = map[string]*env.Builtin{
case xml.StartElement:
return env.String{obj1.Name.Local}
default:
return env.NewError("Not xml-strat element")
return env.NewError("Not xml-start element")
}
default:
return env.NewError("first argument should be native")
Expand Down
12 changes: 6 additions & 6 deletions evaldo/builtins_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ var Builtins_http = map[string]*env.Builtin{
return MakeBuiltinError(ps, "Error in reading client data.", "Go-server-websocket//read")
}
// fmt.Fprintf(path.Value.(http.ResponseWriter), handler.Value)
return env.String{string(msg)}
return env.NewString(string(msg))
default:
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "Go-server-websocket//read")
Expand Down Expand Up @@ -371,7 +371,7 @@ var Builtins_http = map[string]*env.Builtin{
return MakeBuiltinError(ps, "Key is missing.", "Go-server-request//query?")
}
//return env.NewError("XOSADOSADOA SDAS DO" + key.Value)
return env.String{vals[0]}
return env.NewString(vals[0])
default:
ps.FailureFlag = true
return MakeArgError(ps, 2, []env.Type{env.StringType}, "Go-server-request//query?")
Expand Down Expand Up @@ -405,7 +405,7 @@ var Builtins_http = map[string]*env.Builtin{
switch req := arg0.(type) {
case env.Native:
val := req.Value.(*url.URL).Path
return env.String{val}
return env.NewString(val)
default:
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "Go-server-url//path?")
Expand All @@ -426,7 +426,7 @@ var Builtins_http = map[string]*env.Builtin{
ps.FailureFlag = true
return MakeBuiltinError(ps, "Cookie key is missing.", "Go-server-request//cookie-val?")
}
return env.String{cookie.Value}
return env.NewString(cookie.Value)
default:
ps.FailureFlag = true
return MakeArgError(ps, 2, []env.Type{env.StringType}, "Go-server-request//cookie-val?")
Expand Down Expand Up @@ -456,7 +456,7 @@ var Builtins_http = map[string]*env.Builtin{
ps.FailureFlag = true
return MakeBuiltinError(ps, "Value is missing.", "Go-server-request//form?")
}
return env.String{val}
return env.NewString(val)
default:
ps.FailureFlag = true
return MakeArgError(ps, 2, []env.Type{env.StringType}, "Go-server-request//form?")
Expand Down Expand Up @@ -550,7 +550,7 @@ var Builtins_http = map[string]*env.Builtin{
switch req := arg0.(type) {
case env.Native:
r := req.Value.(*multipart.FileHeader)
return env.String{r.Filename}
return env.NewString(r.Filename)
default:
ps.FailureFlag = true
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "rye-multipart-header//filename?")
Expand Down
8 changes: 4 additions & 4 deletions evaldo/builtins_mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var Builtins_mail = map[string]*env.Builtin{
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch email := arg0.(type) {
case env.Native:
return env.String{email.Value.(parsemail.Email).Subject}
return env.NewString(email.Value.(parsemail.Email).Subject)
default:
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "parsed-email//subject?")
}
Expand Down Expand Up @@ -86,7 +86,7 @@ var Builtins_mail = map[string]*env.Builtin{
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch email := arg0.(type) {
case env.Native:
return env.String{email.Value.(parsemail.Email).MessageID}
return env.NewString(email.Value.(parsemail.Email).MessageID)
default:
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "parsed-email//message-id?")
}
Expand All @@ -99,7 +99,7 @@ var Builtins_mail = map[string]*env.Builtin{
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch email := arg0.(type) {
case env.Native:
return env.String{email.Value.(parsemail.Email).HTMLBody}
return env.NewString(email.Value.(parsemail.Email).HTMLBody)
default:
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "parsed-email//html-body?")
}
Expand All @@ -112,7 +112,7 @@ var Builtins_mail = map[string]*env.Builtin{
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch email := arg0.(type) {
case env.Native:
return env.String{email.Value.(parsemail.Email).TextBody}
return env.NewString(email.Value.(parsemail.Email).TextBody)
default:
return MakeArgError(ps, 1, []env.Type{env.NativeType}, "parsed-email//text-body?")
}
Expand Down
2 changes: 1 addition & 1 deletion evaldo/builtins_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var Builtins_mysql = map[string]*env.Builtin{
} else {
num, _ := res.RowsAffected()
if num > 0 {
return env.Integer{1}
return env.NewInteger(1)
} else {
ps.FailureFlag = true
return MakeBuiltinError(ps, "No rows affected.", "Rye-mysql//exec")
Expand Down
2 changes: 1 addition & 1 deletion evaldo/builtins_psql.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var Builtins_psql = map[string]*env.Builtin{
} else {
num, _ := res.RowsAffected()
if num > 0 {
return env.Integer{1}
return env.NewInteger(1)
} else {
ps.FailureFlag = true
return MakeBuiltinError(ps, "No rows affected.", "Rye-psql//exec")
Expand Down
4 changes: 2 additions & 2 deletions evaldo/builtins_psutil.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !no_devops
// +build !no_devops
//go:build add_psutil
// +build add_psutil

package evaldo

Expand Down
4 changes: 2 additions & 2 deletions evaldo/builtins_psutil_not.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build no_devops
// +build no_devops
//go:build !add_psutil
// +build !add_psutil

package evaldo

Expand Down
13 changes: 10 additions & 3 deletions evaldo/builtins_smtpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package evaldo

import (
"bytes"
"fmt"
"net"

"github.com/refaktor/rye/env"
Expand Down Expand Up @@ -33,24 +34,30 @@ var Builtins_smtpd = map[string]*env.Builtin{
case env.Function:
switch name := arg2.(type) {
case env.String:
smtpd.ListenAndServe(server.Value.(env.String).Value,
err := smtpd.ListenAndServe(server.Value.(env.String).Value,
func(origin net.Addr, from string, to []string, data []byte) error {
ps.FailureFlag = false
ps.ErrorFlag = false
ps.ReturnFlag = false
psTemp := env.ProgramState{}
copier.Copy(&psTemp, &ps)
err := copier.Copy(&psTemp, &ps)
if err != nil {
fmt.Println(err.Error()) // TODO
}
// msg, _ := mail.ReadMessage(bytes.NewReader(data))
lstTo := make([]any, len(to))
for i, v := range to {
lstTo[i] = v
}
CallFunctionArgs4(handler, ps, *env.NewNative(ps.Idx, bytes.NewReader(data), "rye-reader"), env.String{from}, *env.NewList(lstTo), *env.NewNative(ps.Idx, origin, "new-addr"), nil)
CallFunctionArgs4(handler, ps, *env.NewNative(ps.Idx, bytes.NewReader(data), "rye-reader"), env.NewString(from), *env.NewList(lstTo), *env.NewNative(ps.Idx, origin, "new-addr"), nil)
//msg, _ := mail.ReadMessage(bytes.NewReader(data))
//subject := msg.Header.Get("Subject")
//log.Printf("Received mail from %s for %s with subject %s", from, to[0], subject)
return nil
}, name.Value, "")
if err != nil {
return makeError(ps, err.Error())
}
return arg0
default:
return MakeArgError(ps, 3, []env.Type{env.StringType}, "smtpd//serve")
Expand Down
6 changes: 3 additions & 3 deletions evaldo/builtins_sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func SQL_EvalBlock(es *env.ProgramState, mode int, values []any) (*env.ProgramSt
//fmt.Println(bu.String())
}
//fmt.Println(bu.String())
es.Res = env.String{bu.String()}
es.Res = env.NewString(bu.String())
return es, values
}

Expand Down Expand Up @@ -85,7 +85,7 @@ func SQL_EvalExpression(es *env.ProgramState, vals []any, mode int) (*env.Progra
fmt.Println("OTHER SQL NODE")
return es, "Error 123112431", vals
}
return es, "ERROR", vals
// return es, "ERROR", vals
}

var Builtins_sqlite = map[string]*env.Builtin{
Expand Down Expand Up @@ -113,7 +113,7 @@ var Builtins_sqlite = map[string]*env.Builtin{
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch str := arg0.(type) {
case env.Spreadsheet:
return env.String{str.ToHtml()}
return env.NewString(str.ToHtml())
default:
return MakeArgError(ps, 1, []env.Type{env.SpreadsheetType}, "htmlize")
}
Expand Down
4 changes: 2 additions & 2 deletions evaldo/builtins_ssh.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !no_ssh
// +build !no_ssh
//go:build add_ssh
// +build add_ssh

package evaldo

Expand Down
4 changes: 2 additions & 2 deletions evaldo/builtins_ssh_not.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build no_ssh
// +build no_ssh
//go:build !add_ssh
// +build !add_ssh

package evaldo

Expand Down
Loading

0 comments on commit fbeccbc

Please sign in to comment.