Skip to content

Commit 8c20a84

Browse files
committed
Reduce surface area of public functions
1 parent a1f5ca5 commit 8c20a84

File tree

10 files changed

+110
-115
lines changed

10 files changed

+110
-115
lines changed

cmd/ari/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,9 @@ func ariMain(cmd *cobra.Command, args []string) int {
353353

354354
func registerCliGoalBindings(ariContext *ari.Context) {
355355
goalContext := ariContext.GoalContext
356-
goalContext.RegisterMonad("tui.color", VFTuiColor)
357-
goalContext.RegisterMonad("tui.style", VFTuiStyle)
358-
goalContext.RegisterDyad("tui.render", VFTuiRender)
356+
goalContext.RegisterMonad("tui.color", vfTuiColor)
357+
goalContext.RegisterMonad("tui.style", vfTuiStyle)
358+
goalContext.RegisterDyad("tui.render", vfTuiRender)
359359
}
360360

361361
func rawREPL(cliSystem *CliSystem) {

cmd/ari/tui.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const (
7373
triadic = 3
7474
)
7575

76-
func VFTuiColor(_ *goal.Context, args []goal.V) goal.V {
76+
func vfTuiColor(_ *goal.Context, args []goal.V) goal.V {
7777
x := args[len(args)-1]
7878
colorS, ok := x.BV().(goal.S)
7979
switch len(args) {
@@ -94,7 +94,7 @@ const quadrilateral = 4
9494
// Implements tui.style monad.
9595
//
9696
//nolint:cyclop,funlen,gocognit,gocyclo // These dictionary translators are best kept together
97-
func VFTuiStyle(_ *goal.Context, args []goal.V) goal.V {
97+
func vfTuiStyle(_ *goal.Context, args []goal.V) goal.V {
9898
x := args[len(args)-1]
9999
styleD, okD := x.BV().(*goal.D)
100100
switch len(args) {
@@ -352,7 +352,7 @@ func VFTuiStyle(_ *goal.Context, args []goal.V) goal.V {
352352
}
353353
}
354354

355-
func VFTuiRender(_ *goal.Context, args []goal.V) goal.V {
355+
func vfTuiRender(_ *goal.Context, args []goal.V) goal.V {
356356
x := args[len(args)-1]
357357
tuiStyle, ok := x.BV().(*TuiStyle)
358358
switch len(args) {

context.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ type Context struct {
8080
}
8181

8282
// Initialize a Goal language context with Ari's extensions.
83-
func NewGoalContext(ariContext *Context, help Help, sqlDatabase *SQLDatabase) (*goal.Context, error) {
83+
func newGoalContext(ariContext *Context, help Help, sqlDatabase *SQLDatabase) (*goal.Context, error) {
8484
goalContext := goal.NewContext()
8585
goalContext.Log = os.Stderr
8686
goalRegisterVariadics(ariContext, goalContext, help, sqlDatabase)
@@ -92,7 +92,7 @@ func NewGoalContext(ariContext *Context, help Help, sqlDatabase *SQLDatabase) (*
9292
}
9393

9494
// Initialize a Goal language context with Ari's extensions.
95-
func NewUniversalGoalContext(ariContext *Context, help Help) (*goal.Context, error) {
95+
func newUniversalGoalContext(ariContext *Context, help Help) (*goal.Context, error) {
9696
goalContext := goal.NewContext()
9797
goalContext.Log = os.Stderr
9898
goalRegisterUniversalVariadics(ariContext, goalContext, help)
@@ -106,11 +106,11 @@ func NewUniversalGoalContext(ariContext *Context, help Help) (*goal.Context, err
106106
// Initialize SQL struct, but don't open the DB yet.
107107
//
108108
// Call SQLDatabase.open to open the database.
109-
func NewSQLDatabase(dataSourceName string) (*SQLDatabase, error) {
110-
return &SQLDatabase{DataSource: dataSourceName, DB: nil, IsOpen: false}, nil
109+
func newSQLDatabase(dataSourceName string) *SQLDatabase {
110+
return &SQLDatabase{DataSource: dataSourceName, DB: nil, IsOpen: false}
111111
}
112112

113-
func NewHelp() map[string]map[string]string {
113+
func newHelp() map[string]map[string]string {
114114
defaultSQLHelp := "A SQL keyword"
115115
goalHelp := GoalKeywordsHelp()
116116
sqlKeywords := SQLKeywords()
@@ -127,7 +127,7 @@ func NewHelp() map[string]map[string]string {
127127
// Initialize a new Context without connecting to the database.
128128
func NewContext(dataSourceName string) (*Context, error) {
129129
ctx := Context{}
130-
helpDictionary := NewHelp()
130+
helpDictionary := newHelp()
131131
ariHelpFunc := func(s string) string {
132132
goalHelp, ok := helpDictionary["goal"]
133133
if !ok {
@@ -141,11 +141,8 @@ func NewContext(dataSourceName string) (*Context, error) {
141141
}
142142
helpFunc := help.Wrap(ariHelpFunc, help.HelpFunc())
143143
help := Help{Dictionary: helpDictionary, Func: helpFunc}
144-
sqlDatabase, err := NewSQLDatabase(dataSourceName)
145-
if err != nil {
146-
return nil, err
147-
}
148-
goalContext, err := NewGoalContext(&ctx, help, sqlDatabase)
144+
sqlDatabase := newSQLDatabase(dataSourceName)
145+
goalContext, err := newGoalContext(&ctx, help, sqlDatabase)
149146
if err != nil {
150147
return nil, err
151148
}
@@ -158,7 +155,7 @@ func NewContext(dataSourceName string) (*Context, error) {
158155
// Initialize a new Context that can be used across platforms, including WASM.
159156
func NewUniversalContext() (*Context, error) {
160157
ctx := Context{}
161-
helpDictionary := NewHelp()
158+
helpDictionary := newHelp()
162159
ariHelpFunc := func(s string) string {
163160
goalHelp, ok := helpDictionary["goal"]
164161
if !ok {
@@ -172,7 +169,7 @@ func NewUniversalContext() (*Context, error) {
172169
}
173170
helpFunc := help.Wrap(ariHelpFunc, help.HelpFunc())
174171
help := Help{Dictionary: helpDictionary, Func: helpFunc}
175-
goalContext, err := NewUniversalGoalContext(&ctx, help)
172+
goalContext, err := newUniversalGoalContext(&ctx, help)
176173
if err != nil {
177174
return nil, err
178175
}

goal.go

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ var goalSourceAri string
8888
// Goal functions implemented in Go
8989

9090
// Implements Goal's help monad + Ari's help dyad.
91-
func VFGoalHelp(help Help) func(_ *goal.Context, args []goal.V) goal.V {
91+
func vfGoalHelp(help Help) func(_ *goal.Context, args []goal.V) goal.V {
9292
return func(_ *goal.Context, args []goal.V) goal.V {
9393
switch len(args) {
9494
case monadic:
@@ -168,60 +168,61 @@ func goalRegisterUniversalVariadics(ariContext *Context, goalContext *goal.Conte
168168
goalContext.RegisterExtension("ari", AriVersion)
169169
goalContext.AssignGlobal("ari.c", goal.NewI(0))
170170
// Monads
171-
goalContext.RegisterMonad("ratelimit.new", VFRateLimitNew)
172-
goalContext.RegisterMonad("ratelimit.take", VFRateLimitTake)
173-
goalContext.RegisterMonad("time.day", VFTimeDay)
174-
goalContext.RegisterMonad("time.hour", VFTimeHour)
175-
goalContext.RegisterMonad("time.loadlocation", VFTimeLoadLocation)
176-
goalContext.RegisterMonad("time.location", VFTimeLocation)
177-
goalContext.RegisterMonad("time.locationstring", VFTimeLocationString)
178-
goalContext.RegisterMonad("time.microsecond", VFTimeMicrosecond)
179-
goalContext.RegisterMonad("time.millisecond", VFTimeMillisecond)
180-
goalContext.RegisterMonad("time.minute", VFTimeMinute)
181-
goalContext.RegisterMonad("time.month", VFTimeMonth)
182-
goalContext.RegisterMonad("time.now", VFTimeNow)
183-
goalContext.RegisterMonad("time.nanosecond", VFTimeNanosecond)
184-
goalContext.RegisterMonad("time.second", VFTimeSecond)
185-
goalContext.RegisterMonad("time.unix", VFTimeUnix)
186-
goalContext.RegisterMonad("time.unixmicro", VFTimeUnixMicro)
187-
goalContext.RegisterMonad("time.unixmilli", VFTimeUnixMilli)
188-
goalContext.RegisterMonad("time.unixnano", VFTimeUnixNano)
189-
goalContext.RegisterMonad("time.utc", VFTimeUTC)
190-
goalContext.RegisterMonad("time.weekday", VFTimeWeekDay)
191-
goalContext.RegisterMonad("time.year", VFTimeYear)
192-
goalContext.RegisterMonad("time.yearday", VFTimeYearDay)
193-
goalContext.RegisterMonad("time.zonename", VFTimeZoneName)
194-
goalContext.RegisterMonad("time.zoneoffset", VFTimeZoneOffset)
195-
goalContext.RegisterMonad("url.encode", VFUrlEncode)
171+
goalContext.RegisterMonad("ratelimit.new", vfRateLimitNew)
172+
goalContext.RegisterMonad("ratelimit.take", vfRateLimitTake)
173+
goalContext.RegisterMonad("time.day", vfTimeDay)
174+
goalContext.RegisterMonad("time.hour", vfTimeHour)
175+
goalContext.RegisterMonad("time.loadlocation", vfTimeLoadLocation)
176+
goalContext.RegisterMonad("time.location", vfTimeLocation)
177+
goalContext.RegisterMonad("time.locationstring", vfTimeLocationString)
178+
goalContext.RegisterMonad("time.microsecond", vfTimeMicrosecond)
179+
goalContext.RegisterMonad("time.millisecond", vfTimeMillisecond)
180+
goalContext.RegisterMonad("time.minute", vfTimeMinute)
181+
goalContext.RegisterMonad("time.month", vfTimeMonth)
182+
goalContext.RegisterMonad("time.now", vfTimeNow)
183+
goalContext.RegisterMonad("time.nanosecond", vfTimeNanosecond)
184+
goalContext.RegisterMonad("time.second", vfTimeSecond)
185+
goalContext.RegisterMonad("time.unix", vfTimeUnix)
186+
goalContext.RegisterMonad("time.unixmicro", vfTimeUnixMicro)
187+
goalContext.RegisterMonad("time.unixmilli", vfTimeUnixMilli)
188+
goalContext.RegisterMonad("time.unixnano", vfTimeUnixNano)
189+
goalContext.RegisterMonad("time.utc", vfTimeUTC)
190+
goalContext.RegisterMonad("time.weekday", vfTimeWeekDay)
191+
goalContext.RegisterMonad("time.year", vfTimeYear)
192+
goalContext.RegisterMonad("time.yearday", vfTimeYearDay)
193+
goalContext.RegisterMonad("time.zonename", vfTimeZoneName)
194+
goalContext.RegisterMonad("time.zoneoffset", vfTimeZoneOffset)
195+
goalContext.RegisterMonad("url.encode", vfURLEncode)
196196
// Dyads
197-
goalContext.RegisterDyad("help", VFGoalHelp(help))
198-
goalContext.RegisterDyad("http.client", VFHTTPClientFn())
199-
goalContext.RegisterDyad("http.delete", VFHTTPMaker(ariContext, "DELETE"))
200-
goalContext.RegisterDyad("http.get", VFHTTPMaker(ariContext, "GET"))
201-
goalContext.RegisterDyad("http.head", VFHTTPMaker(ariContext, "HEAD"))
202-
goalContext.RegisterDyad("http.options", VFHTTPMaker(ariContext, "OPTIONS"))
203-
goalContext.RegisterDyad("http.patch", VFHTTPMaker(ariContext, "PATCH"))
204-
goalContext.RegisterDyad("http.post", VFHTTPMaker(ariContext, "POST"))
205-
goalContext.RegisterDyad("http.put", VFHTTPMaker(ariContext, "PUT"))
206-
goalContext.RegisterDyad("time.add", VFTimeAdd)
207-
goalContext.RegisterDyad("time.date", VFTimeDate)
208-
goalContext.RegisterDyad("time.fixedzone", VFTimeFixedZone)
209-
goalContext.RegisterDyad("time.format", VFTimeFormat)
210-
goalContext.RegisterDyad("time.parse", VFTimeParse)
211-
goalContext.RegisterDyad("time.sub", VFTimeSub)
197+
goalContext.RegisterDyad("help", vfGoalHelp(help))
198+
goalContext.RegisterDyad("http.client", vfHTTPClientFn())
199+
goalContext.RegisterDyad("http.delete", vfHTTPMaker(ariContext, "DELETE"))
200+
goalContext.RegisterDyad("http.get", vfHTTPMaker(ariContext, "GET"))
201+
goalContext.RegisterDyad("http.head", vfHTTPMaker(ariContext, "HEAD"))
202+
goalContext.RegisterDyad("http.options", vfHTTPMaker(ariContext, "OPTIONS"))
203+
goalContext.RegisterDyad("http.patch", vfHTTPMaker(ariContext, "PATCH"))
204+
goalContext.RegisterDyad("http.post", vfHTTPMaker(ariContext, "POST"))
205+
goalContext.RegisterDyad("http.put", vfHTTPMaker(ariContext, "PUT"))
206+
goalContext.RegisterDyad("time.add", vfTimeAdd)
207+
goalContext.RegisterDyad("time.addDate", vfTimeAddDate)
208+
goalContext.RegisterDyad("time.date", vfTimeDate)
209+
goalContext.RegisterDyad("time.fixedZone", vfTimeFixedZone)
210+
goalContext.RegisterDyad("time.format", vfTimeFormat)
211+
goalContext.RegisterDyad("time.parse", vfTimeParse)
212+
goalContext.RegisterDyad("time.sub", vfTimeSub)
212213
// Globals
213214
registerTimeGlobals(goalContext)
214215
}
215216

216217
func goalRegisterVariadics(ariContext *Context, goalContext *goal.Context, help Help, sqlDatabase *SQLDatabase) {
217218
goalRegisterUniversalVariadics(ariContext, goalContext, help)
218219
// Monads
219-
goalContext.RegisterMonad("sql.close", VFSqlClose)
220-
goalContext.RegisterMonad("sql.open", VFSqlOpen)
220+
goalContext.RegisterMonad("sql.close", vfSQLClose)
221+
goalContext.RegisterMonad("sql.open", vfSQLOpen)
221222
// Dyads
222-
goalContext.RegisterDyad("http.serve", VFServe)
223-
goalContext.RegisterDyad("sql.q", VFSqlQFn(sqlDatabase))
224-
goalContext.RegisterDyad("sql.exec", VFSqlExecFn(sqlDatabase))
223+
goalContext.RegisterDyad("http.serve", vfServe)
224+
goalContext.RegisterDyad("sql.q", vfSQLQFn(sqlDatabase))
225+
goalContext.RegisterDyad("sql.exec", vfSQLExecFn(sqlDatabase))
225226
}
226227

227228
//nolint:funlen

http.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (httpClient *HTTPClient) Append(_ *goal.Context, dst []byte, _ bool) []byte
4646
return append(dst, fmt.Sprintf("<%v %#v>", httpClient.Type(), httpClient.Client)...)
4747
}
4848

49-
//nolint:cyclop,funlen,gocognit,gocyclo // No code shared, ball of wax stays together.
49+
//nolint:cyclop,funlen,gocognit,gocyclo // No code shared, ball of wax stays together. Public for tests.
5050
func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
5151
// Not currently implemented:
5252
// Cookies []*http.Cookie // Medium-sized struct
@@ -327,7 +327,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
327327
return &httpClient, nil
328328
}
329329

330-
func VFHTTPClientFn() func(goalContext *goal.Context, args []goal.V) goal.V {
330+
func vfHTTPClientFn() func(goalContext *goal.Context, args []goal.V) goal.V {
331331
return func(_ *goal.Context, args []goal.V) goal.V {
332332
x := args[len(args)-1]
333333
clientOptions, ok := x.BV().(*goal.D)
@@ -347,7 +347,7 @@ func VFHTTPClientFn() func(goalContext *goal.Context, args []goal.V) goal.V {
347347
}
348348
}
349349

350-
func VFHTTPMaker(ariContext *Context, method string) func(goalContext *goal.Context, args []goal.V) goal.V {
350+
func vfHTTPMaker(ariContext *Context, method string) func(goalContext *goal.Context, args []goal.V) goal.V {
351351
methodLower := strings.ToLower(method) // Used for function name
352352
methodUpper := strings.ToUpper(method) // Used by go-resty for HTTP method
353353
return func(_ *goal.Context, args []goal.V) goal.V {
@@ -707,7 +707,7 @@ const (
707707
)
708708

709709
// Implements http.serve dyad.
710-
func VFServe(goalContext *goal.Context, args []goal.V) goal.V {
710+
func vfServe(goalContext *goal.Context, args []goal.V) goal.V {
711711
x := args[len(args)-1]
712712
hostAndPort, ok := x.BV().(goal.S)
713713
if !ok {

ratelimit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (rateLimiter *RateLimiter) Type() string {
3131
return "ari.RateLimiter"
3232
}
3333

34-
func VFRateLimitNew(_ *goal.Context, args []goal.V) goal.V {
34+
func vfRateLimitNew(_ *goal.Context, args []goal.V) goal.V {
3535
if len(args) > 1 {
3636
return goal.Panicf("ratelimit.new : too many arguments (%d), expects 1 argument", len(args))
3737
}
@@ -43,7 +43,7 @@ func VFRateLimitNew(_ *goal.Context, args []goal.V) goal.V {
4343
return panicType("ratelimit.new i", "i", x)
4444
}
4545

46-
func VFRateLimitTake(_ *goal.Context, args []goal.V) goal.V {
46+
func vfRateLimitTake(_ *goal.Context, args []goal.V) goal.V {
4747
if len(args) > 1 {
4848
return goal.Panicf("ratelimit.take : too many arguments (%d), expects 1 argument", len(args))
4949
}

sql.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func SQLExec(sqlDatabase *SQLDatabase, sqlQuery string, args []any) (goal.V, err
176176
}
177177

178178
// Implements sql.open to open a SQL database.
179-
func VFSqlOpen(_ *goal.Context, args []goal.V) goal.V {
179+
func vfSQLOpen(_ *goal.Context, args []goal.V) goal.V {
180180
x := args[len(args)-1]
181181
dataSourceName, ok := x.BV().(goal.S)
182182
switch len(args) {
@@ -185,11 +185,8 @@ func VFSqlOpen(_ *goal.Context, args []goal.V) goal.V {
185185
return panicType("sql.open s", "s", x)
186186
}
187187
dsn := string(dataSourceName)
188-
sqlDatabase, err := NewSQLDatabase(dsn)
189-
if err != nil {
190-
return goal.NewPanicError(err)
191-
}
192-
err = sqlDatabase.Open()
188+
sqlDatabase := newSQLDatabase(dsn)
189+
err := sqlDatabase.Open()
193190
if err != nil {
194191
return goal.NewPanicError(err)
195192
}
@@ -200,7 +197,7 @@ func VFSqlOpen(_ *goal.Context, args []goal.V) goal.V {
200197
}
201198

202199
// Implements sql.close to close the SQL database.
203-
func VFSqlClose(_ *goal.Context, args []goal.V) goal.V {
200+
func vfSQLClose(_ *goal.Context, args []goal.V) goal.V {
204201
x := args[len(args)-1]
205202
sqlDatabase, ok := x.BV().(*SQLDatabase)
206203
switch len(args) {
@@ -219,7 +216,7 @@ func VFSqlClose(_ *goal.Context, args []goal.V) goal.V {
219216
}
220217

221218
// Implements sql.q for SQL querying.
222-
func VFSqlQFn(sqlDatabase *SQLDatabase) func(goalContext *goal.Context, args []goal.V) goal.V {
219+
func vfSQLQFn(sqlDatabase *SQLDatabase) func(goalContext *goal.Context, args []goal.V) goal.V {
223220
return func(goalContext *goal.Context, args []goal.V) goal.V {
224221
x := args[len(args)-1]
225222
switch len(args) {
@@ -272,7 +269,7 @@ func sqlQDyadic(x goal.V, args []goal.V) goal.V {
272269
}
273270

274271
// Implements sql.exec for executing SQL statements.
275-
func VFSqlExecFn(sqlDatabase *SQLDatabase) func(goalContext *goal.Context, args []goal.V) goal.V {
272+
func vfSQLExecFn(sqlDatabase *SQLDatabase) func(goalContext *goal.Context, args []goal.V) goal.V {
276273
return func(goalContext *goal.Context, args []goal.V) goal.V {
277274
x := args[len(args)-1]
278275
switch len(args) {

testing/time-test.goal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ tt.t{pt["2019-02-03T04:00:00.000000000Z"]~time.date[2019;2;3;4]}
3535
tt.t{pt["2019-02-03T04:05:00.000000000Z"]~time.date[2019;2;3;4;5]}
3636
tt.t{pt["2019-02-03T04:05:06.000000000Z"]~time.date[2019;2;3;4;5;6]}
3737
tt.t{pt["2019-02-03T04:05:06.789000000Z"]~time.date[2019;2;3;4;5;6;789000000]}
38-
utc8:time.fixedzone["UTC-8";*/-8 60 60]
38+
utc8:time.fixedZone["UTC-8";*/-8 60 60]
3939
tt.t{time.parse[time.RFC822Z;"03 Feb 19 04:05 -0800"]~time.date[2019;2;3;4;5;0;0;utc8]}
4040
tt.t{"UTC-8"~time.locationstring utc8}
4141
tt.t{time.date[2020;1;1]~t2}

0 commit comments

Comments
 (0)