diff --git a/README.md b/README.md index 100013f..7bbc717 100644 --- a/README.md +++ b/README.md @@ -55,9 +55,10 @@ Flags: - `help` based on Goal's, but allows adding help strings when used dyadically (e.g.,`"sql.q"help"Run SQL query"`) - New Goal functions: - `http.` functions for HTTP requests using [Resty] + - `ratelimit.new` and `ratelimit.take` for rate limiting (leaky bucket algorithm) using [uber-go/ratelimit] - `sql.` functions for SQL queries and commands + - Table-related `csv.tbl` and `json.tbl` to make Goal tables from the output of `csv` and `json` respectively - `tt.` test framework - - `csv.tbl` and `json.tbl` to make Goal tables from the output of `csv` and `json` respectively - `time.` functions for more extensive date/time handling - `tui.` functions for basic terminal UI styling (colors, padding/margin, borders) - Dedicated SQL mode @@ -194,3 +195,4 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. [Goal]: https://codeberg.org/anaseto/goal [Resty]: https://github.com/go-resty/resty +[uber-go/ratelimit]: https://github.com/uber-go/ratelimit diff --git a/cmd/ari/main.go b/cmd/ari/main.go index cb693a1..63fa012 100644 --- a/cmd/ari/main.go +++ b/cmd/ari/main.go @@ -353,9 +353,9 @@ func ariMain(cmd *cobra.Command, args []string) int { func registerCliGoalBindings(ariContext *ari.Context) { goalContext := ariContext.GoalContext - goalContext.RegisterMonad("tui.color", VFTuiColor) - goalContext.RegisterMonad("tui.style", VFTuiStyle) - goalContext.RegisterDyad("tui.render", VFTuiRender) + goalContext.RegisterMonad("tui.color", vfTuiColor) + goalContext.RegisterMonad("tui.style", vfTuiStyle) + goalContext.RegisterDyad("tui.render", vfTuiRender) } func rawREPL(cliSystem *CliSystem) { diff --git a/cmd/ari/tui.go b/cmd/ari/tui.go index ed3d874..ab1c872 100644 --- a/cmd/ari/tui.go +++ b/cmd/ari/tui.go @@ -73,7 +73,7 @@ const ( triadic = 3 ) -func VFTuiColor(_ *goal.Context, args []goal.V) goal.V { +func vfTuiColor(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] colorS, ok := x.BV().(goal.S) switch len(args) { @@ -94,7 +94,7 @@ const quadrilateral = 4 // Implements tui.style monad. // //nolint:cyclop,funlen,gocognit,gocyclo // These dictionary translators are best kept together -func VFTuiStyle(_ *goal.Context, args []goal.V) goal.V { +func vfTuiStyle(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] styleD, okD := x.BV().(*goal.D) switch len(args) { @@ -352,7 +352,7 @@ func VFTuiStyle(_ *goal.Context, args []goal.V) goal.V { } } -func VFTuiRender(_ *goal.Context, args []goal.V) goal.V { +func vfTuiRender(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] tuiStyle, ok := x.BV().(*TuiStyle) switch len(args) { diff --git a/context.go b/context.go index a00036f..8aa53e1 100644 --- a/context.go +++ b/context.go @@ -80,7 +80,7 @@ type Context struct { } // Initialize a Goal language context with Ari's extensions. -func NewGoalContext(ariContext *Context, help Help, sqlDatabase *SQLDatabase) (*goal.Context, error) { +func newGoalContext(ariContext *Context, help Help, sqlDatabase *SQLDatabase) (*goal.Context, error) { goalContext := goal.NewContext() goalContext.Log = os.Stderr goalRegisterVariadics(ariContext, goalContext, help, sqlDatabase) @@ -92,7 +92,7 @@ func NewGoalContext(ariContext *Context, help Help, sqlDatabase *SQLDatabase) (* } // Initialize a Goal language context with Ari's extensions. -func NewUniversalGoalContext(ariContext *Context, help Help) (*goal.Context, error) { +func newUniversalGoalContext(ariContext *Context, help Help) (*goal.Context, error) { goalContext := goal.NewContext() goalContext.Log = os.Stderr goalRegisterUniversalVariadics(ariContext, goalContext, help) @@ -106,11 +106,11 @@ func NewUniversalGoalContext(ariContext *Context, help Help) (*goal.Context, err // Initialize SQL struct, but don't open the DB yet. // // Call SQLDatabase.open to open the database. -func NewSQLDatabase(dataSourceName string) (*SQLDatabase, error) { - return &SQLDatabase{DataSource: dataSourceName, DB: nil, IsOpen: false}, nil +func newSQLDatabase(dataSourceName string) *SQLDatabase { + return &SQLDatabase{DataSource: dataSourceName, DB: nil, IsOpen: false} } -func NewHelp() map[string]map[string]string { +func newHelp() map[string]map[string]string { defaultSQLHelp := "A SQL keyword" goalHelp := GoalKeywordsHelp() sqlKeywords := SQLKeywords() @@ -127,7 +127,7 @@ func NewHelp() map[string]map[string]string { // Initialize a new Context without connecting to the database. func NewContext(dataSourceName string) (*Context, error) { ctx := Context{} - helpDictionary := NewHelp() + helpDictionary := newHelp() ariHelpFunc := func(s string) string { goalHelp, ok := helpDictionary["goal"] if !ok { @@ -141,11 +141,8 @@ func NewContext(dataSourceName string) (*Context, error) { } helpFunc := help.Wrap(ariHelpFunc, help.HelpFunc()) help := Help{Dictionary: helpDictionary, Func: helpFunc} - sqlDatabase, err := NewSQLDatabase(dataSourceName) - if err != nil { - return nil, err - } - goalContext, err := NewGoalContext(&ctx, help, sqlDatabase) + sqlDatabase := newSQLDatabase(dataSourceName) + goalContext, err := newGoalContext(&ctx, help, sqlDatabase) if err != nil { return nil, err } @@ -158,7 +155,7 @@ func NewContext(dataSourceName string) (*Context, error) { // Initialize a new Context that can be used across platforms, including WASM. func NewUniversalContext() (*Context, error) { ctx := Context{} - helpDictionary := NewHelp() + helpDictionary := newHelp() ariHelpFunc := func(s string) string { goalHelp, ok := helpDictionary["goal"] if !ok { @@ -172,7 +169,7 @@ func NewUniversalContext() (*Context, error) { } helpFunc := help.Wrap(ariHelpFunc, help.HelpFunc()) help := Help{Dictionary: helpDictionary, Func: helpFunc} - goalContext, err := NewUniversalGoalContext(&ctx, help) + goalContext, err := newUniversalGoalContext(&ctx, help) if err != nil { return nil, err } diff --git a/goal.go b/goal.go index c7632ea..63e3f50 100644 --- a/goal.go +++ b/goal.go @@ -88,7 +88,7 @@ var goalSourceAri string // Goal functions implemented in Go // Implements Goal's help monad + Ari's help dyad. -func VFGoalHelp(help Help) func(_ *goal.Context, args []goal.V) goal.V { +func vfGoalHelp(help Help) func(_ *goal.Context, args []goal.V) goal.V { return func(_ *goal.Context, args []goal.V) goal.V { switch len(args) { case monadic: @@ -168,47 +168,48 @@ func goalRegisterUniversalVariadics(ariContext *Context, goalContext *goal.Conte goalContext.RegisterExtension("ari", AriVersion) goalContext.AssignGlobal("ari.c", goal.NewI(0)) // Monads - goalContext.RegisterMonad("ratelimit.new", VFRateLimitNew) - goalContext.RegisterMonad("ratelimit.take", VFRateLimitTake) - goalContext.RegisterMonad("time.day", VFTimeDay) - goalContext.RegisterMonad("time.hour", VFTimeHour) - goalContext.RegisterMonad("time.loadlocation", VFTimeLoadLocation) - goalContext.RegisterMonad("time.location", VFTimeLocation) - goalContext.RegisterMonad("time.locationstring", VFTimeLocationString) - goalContext.RegisterMonad("time.microsecond", VFTimeMicrosecond) - goalContext.RegisterMonad("time.millisecond", VFTimeMillisecond) - goalContext.RegisterMonad("time.minute", VFTimeMinute) - goalContext.RegisterMonad("time.month", VFTimeMonth) - goalContext.RegisterMonad("time.now", VFTimeNow) - goalContext.RegisterMonad("time.nanosecond", VFTimeNanosecond) - goalContext.RegisterMonad("time.second", VFTimeSecond) - goalContext.RegisterMonad("time.unix", VFTimeUnix) - goalContext.RegisterMonad("time.unixmicro", VFTimeUnixMicro) - goalContext.RegisterMonad("time.unixmilli", VFTimeUnixMilli) - goalContext.RegisterMonad("time.unixnano", VFTimeUnixNano) - goalContext.RegisterMonad("time.utc", VFTimeUTC) - goalContext.RegisterMonad("time.weekday", VFTimeWeekDay) - goalContext.RegisterMonad("time.year", VFTimeYear) - goalContext.RegisterMonad("time.yearday", VFTimeYearDay) - goalContext.RegisterMonad("time.zonename", VFTimeZoneName) - goalContext.RegisterMonad("time.zoneoffset", VFTimeZoneOffset) - goalContext.RegisterMonad("url.encode", VFUrlEncode) + goalContext.RegisterMonad("ratelimit.new", vfRateLimitNew) + goalContext.RegisterMonad("ratelimit.take", vfRateLimitTake) + goalContext.RegisterMonad("time.day", vfTimeDay) + goalContext.RegisterMonad("time.hour", vfTimeHour) + goalContext.RegisterMonad("time.loadlocation", vfTimeLoadLocation) + goalContext.RegisterMonad("time.location", vfTimeLocation) + goalContext.RegisterMonad("time.locationstring", vfTimeLocationString) + goalContext.RegisterMonad("time.microsecond", vfTimeMicrosecond) + goalContext.RegisterMonad("time.millisecond", vfTimeMillisecond) + goalContext.RegisterMonad("time.minute", vfTimeMinute) + goalContext.RegisterMonad("time.month", vfTimeMonth) + goalContext.RegisterMonad("time.now", vfTimeNow) + goalContext.RegisterMonad("time.nanosecond", vfTimeNanosecond) + goalContext.RegisterMonad("time.second", vfTimeSecond) + goalContext.RegisterMonad("time.unix", vfTimeUnix) + goalContext.RegisterMonad("time.unixmicro", vfTimeUnixMicro) + goalContext.RegisterMonad("time.unixmilli", vfTimeUnixMilli) + goalContext.RegisterMonad("time.unixnano", vfTimeUnixNano) + goalContext.RegisterMonad("time.utc", vfTimeUTC) + goalContext.RegisterMonad("time.weekday", vfTimeWeekDay) + goalContext.RegisterMonad("time.year", vfTimeYear) + goalContext.RegisterMonad("time.yearday", vfTimeYearDay) + goalContext.RegisterMonad("time.zonename", vfTimeZoneName) + goalContext.RegisterMonad("time.zoneoffset", vfTimeZoneOffset) + goalContext.RegisterMonad("url.encode", vfURLEncode) // Dyads - goalContext.RegisterDyad("help", VFGoalHelp(help)) - goalContext.RegisterDyad("http.client", VFHTTPClientFn()) - goalContext.RegisterDyad("http.delete", VFHTTPMaker(ariContext, "DELETE")) - goalContext.RegisterDyad("http.get", VFHTTPMaker(ariContext, "GET")) - goalContext.RegisterDyad("http.head", VFHTTPMaker(ariContext, "HEAD")) - goalContext.RegisterDyad("http.options", VFHTTPMaker(ariContext, "OPTIONS")) - goalContext.RegisterDyad("http.patch", VFHTTPMaker(ariContext, "PATCH")) - goalContext.RegisterDyad("http.post", VFHTTPMaker(ariContext, "POST")) - goalContext.RegisterDyad("http.put", VFHTTPMaker(ariContext, "PUT")) - goalContext.RegisterDyad("time.add", VFTimeAdd) - goalContext.RegisterDyad("time.date", VFTimeDate) - goalContext.RegisterDyad("time.fixedzone", VFTimeFixedZone) - goalContext.RegisterDyad("time.format", VFTimeFormat) - goalContext.RegisterDyad("time.parse", VFTimeParse) - goalContext.RegisterDyad("time.sub", VFTimeSub) + goalContext.RegisterDyad("help", vfGoalHelp(help)) + goalContext.RegisterDyad("http.client", vfHTTPClientFn()) + goalContext.RegisterDyad("http.delete", vfHTTPMaker(ariContext, "DELETE")) + goalContext.RegisterDyad("http.get", vfHTTPMaker(ariContext, "GET")) + goalContext.RegisterDyad("http.head", vfHTTPMaker(ariContext, "HEAD")) + goalContext.RegisterDyad("http.options", vfHTTPMaker(ariContext, "OPTIONS")) + goalContext.RegisterDyad("http.patch", vfHTTPMaker(ariContext, "PATCH")) + goalContext.RegisterDyad("http.post", vfHTTPMaker(ariContext, "POST")) + goalContext.RegisterDyad("http.put", vfHTTPMaker(ariContext, "PUT")) + goalContext.RegisterDyad("time.add", vfTimeAdd) + goalContext.RegisterDyad("time.addDate", vfTimeAddDate) + goalContext.RegisterDyad("time.date", vfTimeDate) + goalContext.RegisterDyad("time.fixedZone", vfTimeFixedZone) + goalContext.RegisterDyad("time.format", vfTimeFormat) + goalContext.RegisterDyad("time.parse", vfTimeParse) + goalContext.RegisterDyad("time.sub", vfTimeSub) // Globals registerTimeGlobals(goalContext) } @@ -216,12 +217,12 @@ func goalRegisterUniversalVariadics(ariContext *Context, goalContext *goal.Conte func goalRegisterVariadics(ariContext *Context, goalContext *goal.Context, help Help, sqlDatabase *SQLDatabase) { goalRegisterUniversalVariadics(ariContext, goalContext, help) // Monads - goalContext.RegisterMonad("sql.close", VFSqlClose) - goalContext.RegisterMonad("sql.open", VFSqlOpen) + goalContext.RegisterMonad("sql.close", vfSQLClose) + goalContext.RegisterMonad("sql.open", vfSQLOpen) // Dyads - goalContext.RegisterDyad("http.serve", VFServe) - goalContext.RegisterDyad("sql.q", VFSqlQFn(sqlDatabase)) - goalContext.RegisterDyad("sql.exec", VFSqlExecFn(sqlDatabase)) + goalContext.RegisterDyad("http.serve", vfServe) + goalContext.RegisterDyad("sql.q", vfSQLQFn(sqlDatabase)) + goalContext.RegisterDyad("sql.exec", vfSQLExecFn(sqlDatabase)) } //nolint:funlen diff --git a/http.go b/http.go index 4c6ffdf..da6c02a 100644 --- a/http.go +++ b/http.go @@ -46,7 +46,7 @@ func (httpClient *HTTPClient) Append(_ *goal.Context, dst []byte, _ bool) []byte return append(dst, fmt.Sprintf("<%v %#v>", httpClient.Type(), httpClient.Client)...) } -//nolint:cyclop,funlen,gocognit,gocyclo // No code shared, ball of wax stays together. +//nolint:cyclop,funlen,gocognit,gocyclo // No code shared, ball of wax stays together. Public for tests. func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) { // Not currently implemented: // Cookies []*http.Cookie // Medium-sized struct @@ -327,7 +327,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) { return &httpClient, nil } -func VFHTTPClientFn() func(goalContext *goal.Context, args []goal.V) goal.V { +func vfHTTPClientFn() func(goalContext *goal.Context, args []goal.V) goal.V { return func(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] clientOptions, ok := x.BV().(*goal.D) @@ -347,7 +347,7 @@ func VFHTTPClientFn() func(goalContext *goal.Context, args []goal.V) goal.V { } } -func VFHTTPMaker(ariContext *Context, method string) func(goalContext *goal.Context, args []goal.V) goal.V { +func vfHTTPMaker(ariContext *Context, method string) func(goalContext *goal.Context, args []goal.V) goal.V { methodLower := strings.ToLower(method) // Used for function name methodUpper := strings.ToUpper(method) // Used by go-resty for HTTP method return func(_ *goal.Context, args []goal.V) goal.V { @@ -707,7 +707,7 @@ const ( ) // Implements http.serve dyad. -func VFServe(goalContext *goal.Context, args []goal.V) goal.V { +func vfServe(goalContext *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] hostAndPort, ok := x.BV().(goal.S) if !ok { diff --git a/ratelimit.go b/ratelimit.go index 201a8c9..4c953e3 100644 --- a/ratelimit.go +++ b/ratelimit.go @@ -31,7 +31,7 @@ func (rateLimiter *RateLimiter) Type() string { return "ari.RateLimiter" } -func VFRateLimitNew(_ *goal.Context, args []goal.V) goal.V { +func vfRateLimitNew(_ *goal.Context, args []goal.V) goal.V { if len(args) > 1 { return goal.Panicf("ratelimit.new : too many arguments (%d), expects 1 argument", len(args)) } @@ -43,7 +43,7 @@ func VFRateLimitNew(_ *goal.Context, args []goal.V) goal.V { return panicType("ratelimit.new i", "i", x) } -func VFRateLimitTake(_ *goal.Context, args []goal.V) goal.V { +func vfRateLimitTake(_ *goal.Context, args []goal.V) goal.V { if len(args) > 1 { return goal.Panicf("ratelimit.take : too many arguments (%d), expects 1 argument", len(args)) } diff --git a/sql.go b/sql.go index 98fd423..a4465ea 100644 --- a/sql.go +++ b/sql.go @@ -176,7 +176,7 @@ func SQLExec(sqlDatabase *SQLDatabase, sqlQuery string, args []any) (goal.V, err } // Implements sql.open to open a SQL database. -func VFSqlOpen(_ *goal.Context, args []goal.V) goal.V { +func vfSQLOpen(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] dataSourceName, ok := x.BV().(goal.S) switch len(args) { @@ -185,11 +185,8 @@ func VFSqlOpen(_ *goal.Context, args []goal.V) goal.V { return panicType("sql.open s", "s", x) } dsn := string(dataSourceName) - sqlDatabase, err := NewSQLDatabase(dsn) - if err != nil { - return goal.NewPanicError(err) - } - err = sqlDatabase.Open() + sqlDatabase := newSQLDatabase(dsn) + err := sqlDatabase.Open() if err != nil { return goal.NewPanicError(err) } @@ -200,7 +197,7 @@ func VFSqlOpen(_ *goal.Context, args []goal.V) goal.V { } // Implements sql.close to close the SQL database. -func VFSqlClose(_ *goal.Context, args []goal.V) goal.V { +func vfSQLClose(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] sqlDatabase, ok := x.BV().(*SQLDatabase) switch len(args) { @@ -219,7 +216,7 @@ func VFSqlClose(_ *goal.Context, args []goal.V) goal.V { } // Implements sql.q for SQL querying. -func VFSqlQFn(sqlDatabase *SQLDatabase) func(goalContext *goal.Context, args []goal.V) goal.V { +func vfSQLQFn(sqlDatabase *SQLDatabase) func(goalContext *goal.Context, args []goal.V) goal.V { return func(goalContext *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { @@ -272,7 +269,7 @@ func sqlQDyadic(x goal.V, args []goal.V) goal.V { } // Implements sql.exec for executing SQL statements. -func VFSqlExecFn(sqlDatabase *SQLDatabase) func(goalContext *goal.Context, args []goal.V) goal.V { +func vfSQLExecFn(sqlDatabase *SQLDatabase) func(goalContext *goal.Context, args []goal.V) goal.V { return func(goalContext *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { diff --git a/testing/time-test.goal b/testing/time-test.goal index 1dfb24d..660aafe 100644 --- a/testing/time-test.goal +++ b/testing/time-test.goal @@ -35,7 +35,7 @@ tt.t{pt["2019-02-03T04:00:00.000000000Z"]~time.date[2019;2;3;4]} tt.t{pt["2019-02-03T04:05:00.000000000Z"]~time.date[2019;2;3;4;5]} tt.t{pt["2019-02-03T04:05:06.000000000Z"]~time.date[2019;2;3;4;5;6]} tt.t{pt["2019-02-03T04:05:06.789000000Z"]~time.date[2019;2;3;4;5;6;789000000]} -utc8:time.fixedzone["UTC-8";*/-8 60 60] +utc8:time.fixedZone["UTC-8";*/-8 60 60] tt.t{time.parse[time.RFC822Z;"03 Feb 19 04:05 -0800"]~time.date[2019;2;3;4;5;0;0;utc8]} tt.t{"UTC-8"~time.locationstring utc8} tt.t{time.date[2020;1;1]~t2} diff --git a/time.go b/time.go index bb2fe57..78ce43d 100644 --- a/time.go +++ b/time.go @@ -77,7 +77,7 @@ func (location *Location) Type() string { // Implements time.date function. // //nolint:cyclop,funlen,gocognit,gocyclo // the different arities are flat and similar, keeping them close is better -func VFTimeDate(_ *goal.Context, args []goal.V) goal.V { +func vfTimeDate(_ *goal.Context, args []goal.V) goal.V { // year int, month Month, day, hour, min, sec, nsec int, loc *Location switch len(args) { case monadic: @@ -318,13 +318,13 @@ func VFTimeDate(_ *goal.Context, args []goal.V) goal.V { } // Implements time.now function. -func VFTimeNow(_ *goal.Context, _ []goal.V) goal.V { +func vfTimeNow(_ *goal.Context, _ []goal.V) goal.V { now := time.Now() return goal.NewV(&Time{&now}) } // Implements time.unix function. -func VFTimeUnix(_ *goal.Context, args []goal.V) goal.V { +func vfTimeUnix(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -356,7 +356,7 @@ func VFTimeUnix(_ *goal.Context, args []goal.V) goal.V { } // Implements time.year function. -func VFTimeYear(_ *goal.Context, args []goal.V) goal.V { +func vfTimeYear(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -372,7 +372,7 @@ func VFTimeYear(_ *goal.Context, args []goal.V) goal.V { } // Implements time.yearday function. -func VFTimeYearDay(_ *goal.Context, args []goal.V) goal.V { +func vfTimeYearDay(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -388,7 +388,7 @@ func VFTimeYearDay(_ *goal.Context, args []goal.V) goal.V { } // Implements time.month function (January = 1). -func VFTimeMonth(_ *goal.Context, args []goal.V) goal.V { +func vfTimeMonth(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -406,7 +406,7 @@ func VFTimeMonth(_ *goal.Context, args []goal.V) goal.V { // CONSIDER: ISOWeek which is a tuple of year, week // Implements time.day function, for day of month. -func VFTimeDay(_ *goal.Context, args []goal.V) goal.V { +func vfTimeDay(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -433,7 +433,7 @@ func VFTimeDay(_ *goal.Context, args []goal.V) goal.V { } // Implements time.weekday function, for day of week (Sunday = 0). -func VFTimeWeekDay(_ *goal.Context, args []goal.V) goal.V { +func vfTimeWeekDay(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -460,7 +460,7 @@ func VFTimeWeekDay(_ *goal.Context, args []goal.V) goal.V { } // Implements time.hour function. -func VFTimeHour(_ *goal.Context, args []goal.V) goal.V { +func vfTimeHour(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -487,7 +487,7 @@ func VFTimeHour(_ *goal.Context, args []goal.V) goal.V { } // Implements time.minute function. -func VFTimeMinute(_ *goal.Context, args []goal.V) goal.V { +func vfTimeMinute(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -514,7 +514,7 @@ func VFTimeMinute(_ *goal.Context, args []goal.V) goal.V { } // Implements time.second function. -func VFTimeSecond(_ *goal.Context, args []goal.V) goal.V { +func vfTimeSecond(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -541,12 +541,12 @@ func VFTimeSecond(_ *goal.Context, args []goal.V) goal.V { } // Implements time.millisecond function. -func VFTimeMillisecond(_ *goal.Context, args []goal.V) goal.V { +func vfTimeMillisecond(_ *goal.Context, args []goal.V) goal.V { return vfTimeMilliMicro("time.millisecond", time.Millisecond, args) } // Implements time.microsecond function. -func VFTimeMicrosecond(_ *goal.Context, args []goal.V) goal.V { +func vfTimeMicrosecond(_ *goal.Context, args []goal.V) goal.V { return vfTimeMilliMicro("time.microsecond", time.Microsecond, args) } @@ -578,7 +578,7 @@ func vfTimeMilliMicro(goalName string, unit time.Duration, args []goal.V) goal.V } // Implements time.nanosecond function. -func VFTimeNanosecond(_ *goal.Context, args []goal.V) goal.V { +func vfTimeNanosecond(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -605,7 +605,7 @@ func VFTimeNanosecond(_ *goal.Context, args []goal.V) goal.V { } // Implements time.zonename function. -func VFTimeZoneName(_ *goal.Context, args []goal.V) goal.V { +func vfTimeZoneName(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -635,7 +635,7 @@ func VFTimeZoneName(_ *goal.Context, args []goal.V) goal.V { } // Implements time.zoneoffset function. -func VFTimeZoneOffset(_ *goal.Context, args []goal.V) goal.V { +func vfTimeZoneOffset(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -665,7 +665,7 @@ func VFTimeZoneOffset(_ *goal.Context, args []goal.V) goal.V { } // Implements time.location function. -func VFTimeLocation(_ *goal.Context, args []goal.V) goal.V { +func vfTimeLocation(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -694,7 +694,7 @@ func VFTimeLocation(_ *goal.Context, args []goal.V) goal.V { } // Implements time.locationstring function. -func VFTimeLocationString(_ *goal.Context, args []goal.V) goal.V { +func vfTimeLocationString(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -721,27 +721,27 @@ func VFTimeLocationString(_ *goal.Context, args []goal.V) goal.V { } } -// Implements time.fixedzone dyad. -func VFTimeFixedZone(_ *goal.Context, args []goal.V) goal.V { +// Implements time.fixedZone dyad. +func vfTimeFixedZone(_ *goal.Context, args []goal.V) goal.V { switch len(args) { case dyadic: x, ok := args[1].BV().(goal.S) if !ok { - return panicType("time.fixedzone name offset-seconds-east-of-utc", "name", args[1]) + return panicType("time.fixedZone name offset-seconds-east-of-utc", "name", args[1]) } y := args[0] if !y.IsI() { - return panicType("time.fixedzone name offset-seconds-east-of-utc", "offset-seconds-east-of-utc", args[0]) + return panicType("time.fixedZone name offset-seconds-east-of-utc", "offset-seconds-east-of-utc", args[0]) } loc := time.FixedZone(string(x), int(y.I())) return goal.NewV(&Location{Location: loc}) default: - return goal.Panicf("time.fixedzone : wrong number of arguments (%d), expects 2 arguments", len(args)) + return goal.Panicf("time.fixedZone : wrong number of arguments (%d), expects 2 arguments", len(args)) } } // Implements time.loadlocation monad. -func VFTimeLoadLocation(_ *goal.Context, args []goal.V) goal.V { +func vfTimeLoadLocation(_ *goal.Context, args []goal.V) goal.V { switch len(args) { case monadic: name, ok := args[0].BV().(goal.S) @@ -764,7 +764,7 @@ func VFTimeLoadLocation(_ *goal.Context, args []goal.V) goal.V { // Given numbers, produces times; given times, produces numbers. // //nolint:dupl // yes, but not interested in further conditional logic here. -func VFTimeUnixMilli(_ *goal.Context, args []goal.V) goal.V { +func vfTimeUnixMilli(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -813,7 +813,7 @@ func VFTimeUnixMilli(_ *goal.Context, args []goal.V) goal.V { // Given numbers, produces times; given times, produces numbers. // //nolint:dupl // yes, but not interested in further conditional logic here. -func VFTimeUnixMicro(_ *goal.Context, args []goal.V) goal.V { +func vfTimeUnixMicro(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -863,7 +863,7 @@ func VFTimeUnixMicro(_ *goal.Context, args []goal.V) goal.V { // Given how Go's time API is designed, the latter case is handled by dividing // the given number by time.Second so that the time.Unix(sec int64, nsec int64) // function can be used to construct the appropriate time struct. -func VFTimeUnixNano(_ *goal.Context, args []goal.V) goal.V { +func vfTimeUnixNano(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -902,7 +902,7 @@ func unixNano(nanos int64) *time.Time { } // Implements time.utc function. -func VFTimeUTC(_ *goal.Context, args []goal.V) goal.V { +func vfTimeUTC(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch len(args) { case monadic: @@ -931,7 +931,7 @@ func VFTimeUTC(_ *goal.Context, args []goal.V) goal.V { } // Implements time.parse function. -func VFTimeParse(_ *goal.Context, args []goal.V) goal.V { +func vfTimeParse(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] layoutS, ok := x.BV().(goal.S) if !ok { @@ -971,7 +971,7 @@ func VFTimeParse(_ *goal.Context, args []goal.V) goal.V { } // Implements time.format function. -func VFTimeFormat(_ *goal.Context, args []goal.V) goal.V { +func vfTimeFormat(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] formatS, ok := x.BV().(goal.S) if !ok { @@ -1016,7 +1016,7 @@ const ( // // Accepts one time argument and one integer argument, returning a new time which is addition // of the integer argument as nanoseconds to the time. Pervasive. -func VFTimeAdd(_ *goal.Context, args []goal.V) goal.V { +func vfTimeAdd(_ *goal.Context, args []goal.V) goal.V { if len(args) > dyadic { return goal.Panicf("time.add : too many arguments (%d), expects 2 arguments", len(args)) } @@ -1094,7 +1094,7 @@ func addTimeV(x *Time, y goal.V) goal.V { } // Implements time.addDate function. -func VFTimeAddDate(_ *goal.Context, args []goal.V) goal.V { +func vfTimeAddDate(_ *goal.Context, args []goal.V) goal.V { if len(args) > dyadic { return goal.Panicf("time.addDate : too many arguments (%d), expects 2 arguments", len(args)) } @@ -1169,7 +1169,7 @@ func adddateTimeV(x *Time, y goal.V) goal.V { } // Implements time.sub function. -func VFTimeSub(_ *goal.Context, args []goal.V) goal.V { +func vfTimeSub(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] t1, ok := x.BV().(*Time) if !ok { diff --git a/url.go b/url.go index 9449c4d..9f98c87 100644 --- a/url.go +++ b/url.go @@ -7,7 +7,7 @@ import ( ) // Implements url.encode. -func VFUrlEncode(_ *goal.Context, args []goal.V) goal.V { +func vfURLEncode(_ *goal.Context, args []goal.V) goal.V { x := args[len(args)-1] switch arg := x.BV().(type) { case goal.S: