44 "encoding/json"
55 "fmt"
66 "io"
7- "log"
7+ "log/slog "
88 "net/http"
99 "os"
1010 "path/filepath"
@@ -107,7 +107,7 @@ func fetchGitHubDirectory(gh GitHubDictionary) (fetchedDictionaries, error) {
107107 owner , repo , ref , path := m [1 ], m [2 ], m [3 ], m [4 ]
108108
109109 apiURL := fmt .Sprintf ("https://api.github.com/repos/%s/%s/contents/%s?ref=%s" , owner , repo , path , ref )
110- log . Printf ( "aspell dictionaries: listing GitHub directory: %s " , apiURL )
110+ slog . Info ( " listing GitHub dictionary directory" , "url " , apiURL )
111111
112112 req , err := http .NewRequest ("GET" , apiURL , nil )
113113 if err != nil {
@@ -119,7 +119,7 @@ func fetchGitHubDirectory(gh GitHubDictionary) (fetchedDictionaries, error) {
119119 if token != "" {
120120 req .Header .Set ("Authorization" , "Bearer " + token )
121121 } else {
122- log . Printf ( "aspell dictionaries: warning: token env %s is empty" , gh .TokenEnv )
122+ slog . Warn ( "dictionary token env is empty" , "env " , gh .TokenEnv )
123123 }
124124 }
125125
@@ -148,7 +148,7 @@ func fetchGitHubDirectory(gh GitHubDictionary) (fetchedDictionaries, error) {
148148 if entry .DownloadURL == "" {
149149 continue
150150 }
151- log . Printf ( "aspell dictionaries: fetching %s " , entry .DownloadURL )
151+ slog . Info ( " fetching dictionary" , "url " , entry .DownloadURL )
152152 fetched , err := fetchSingleFile (entry .DownloadURL , entry .Name , gh .TokenEnv )
153153 if err != nil {
154154 return result , fmt .Errorf ("fetching %s: %w" , entry .Name , err )
@@ -157,7 +157,7 @@ func fetchGitHubDirectory(gh GitHubDictionary) (fetchedDictionaries, error) {
157157 result .rwsFiles = append (result .rwsFiles , fetched .rwsFiles ... )
158158 }
159159
160- log . Printf ( "aspell dictionaries: loaded %d words and %d .rws files from %s " , len (result .words ), len (result .rwsFiles ), gh .URL )
160+ slog . Info ( "loaded dictionaries" , " words" , len (result .words ), "rwsFiles" , len (result .rwsFiles ), "url" , gh .URL )
161161 return result , nil
162162}
163163
@@ -176,7 +176,7 @@ func fetchGitLabDirectory(gl GitLabDictionary) (fetchedDictionaries, error) {
176176 encodedProject := strings .ReplaceAll (project , "/" , "%2F" )
177177 apiURL := fmt .Sprintf ("%s/api/v4/projects/%s/repository/tree?path=%s&ref=%s&per_page=100" ,
178178 baseURL , encodedProject , path , ref )
179- log . Printf ( "aspell dictionaries: listing GitLab directory: %s " , apiURL )
179+ slog . Info ( " listing GitLab dictionary directory" , "url " , apiURL )
180180
181181 req , err := http .NewRequest ("GET" , apiURL , nil )
182182 if err != nil {
@@ -210,7 +210,7 @@ func fetchGitLabDirectory(gl GitLabDictionary) (fetchedDictionaries, error) {
210210 encodedPath := strings .ReplaceAll (entry .Path , "/" , "%2F" )
211211 rawURL := fmt .Sprintf ("%s/api/v4/projects/%s/repository/files/%s/raw?ref=%s" ,
212212 baseURL , encodedProject , encodedPath , ref )
213- log . Printf ( "aspell dictionaries: fetching %s " , rawURL )
213+ slog . Info ( " fetching dictionary" , "url " , rawURL )
214214 fetched , err := fetchSingleFile (rawURL , entry .Name , gl .TokenEnv )
215215 if err != nil {
216216 return result , fmt .Errorf ("fetching %s: %w" , entry .Name , err )
@@ -219,7 +219,7 @@ func fetchGitLabDirectory(gl GitLabDictionary) (fetchedDictionaries, error) {
219219 result .rwsFiles = append (result .rwsFiles , fetched .rwsFiles ... )
220220 }
221221
222- log . Printf ( "aspell dictionaries: loaded %d words and %d .rws files from %s " , len (result .words ), len (result .rwsFiles ), gl .URL )
222+ slog . Info ( "loaded dictionaries" , " words" , len (result .words ), "rwsFiles" , len (result .rwsFiles ), "url" , gl .URL )
223223 return result , nil
224224}
225225
@@ -229,7 +229,7 @@ func setGitLabToken(req *http.Request, tokenEnv string) {
229229 }
230230 token := os .Getenv (tokenEnv )
231231 if token == "" {
232- log . Printf ( "aspell dictionaries: warning: token env %s is empty" , tokenEnv )
232+ slog . Warn ( "dictionary token env is empty" , "env " , tokenEnv )
233233 return
234234 }
235235 req .Header .Set ("PRIVATE-TOKEN" , token )
@@ -238,7 +238,7 @@ func setGitLabToken(req *http.Request, tokenEnv string) {
238238// fetchDictionaryURL fetches a single dictionary file from a URL.
239239func fetchDictionaryURL (rawURL string ) (fetchedDictionaries , error ) {
240240 name := filepath .Base (rawURL )
241- log . Printf ( "aspell dictionaries: fetching %s " , rawURL )
241+ slog . Info ( " fetching dictionary" , "url " , rawURL )
242242 return fetchSingleFile (rawURL , name , "" )
243243}
244244
@@ -290,16 +290,16 @@ func fetchSingleFile(url, name, tokenEnv string) (fetchedDictionaries, error) {
290290 }
291291 _ = tmpFile .Close ()
292292 result .rwsFiles = append (result .rwsFiles , tmpFile .Name ())
293- log . Printf ( "aspell dictionaries: saved .rws dictionary %s to %s" , name , tmpFile .Name ())
293+ slog . Info ( " saved .rws dictionary" , "file" , name , "path" , tmpFile .Name ())
294294 case strings .HasSuffix (lower , ".txt" ):
295295 words := parseTxtDictionary (string (data ))
296296 result .words = append (result .words , words ... )
297- log . Printf ( "aspell dictionaries: loaded %d words from %s" , len (words ), name )
297+ slog . Info ( " loaded dictionary words" , "count" , len (words ), "file" , name )
298298 default :
299299 // Treat unknown extensions as plain text word lists
300300 words := parseTxtDictionary (string (data ))
301301 result .words = append (result .words , words ... )
302- log . Printf ( "aspell dictionaries: loaded %d words from %s (treated as text) " , len (words ), name )
302+ slog . Info ( " loaded dictionary words as plain text" , "count" , len (words ), "file" , name )
303303 }
304304
305305 return result , nil
0 commit comments