Re: [go-nuts] Is there a way to specify or use the tmp directory used in testing?

2022-02-25 Thread Leam Hall

My apologies for taking so long to respond; a new job and cold weather have 
taken up most of my time.

I have two versions of the application; one CLI and one web. The programs create 
characters for games and fiction, and use data text files relative to the binary ( 
/data/* ) to get names. The reason for not embedding names into the 
binary is so the data files can be altered to suit the user's needs. They may want 
Elven names, or Chinese, or whatever. The web program also uses template files, but 
those could probably be embedded.

The tests for the CLI work 
(https://github.com/makhidkarun/crewgen/blob/master/cmd/teamgen/main_test.go), but I have 
not figured out how to make the web version tests work 
(https://github.com/makhidkarun/crewgen/blob/master/cmd/crewgen/main_test.go). If I 
uncomment lines 38-57 of the web tests and run "go test" in that directory, I 
get:

###
Building crewgen...
Running crewgen tests...
Running in /tmp/TestHandleDocroot84710494/001, with 
/home/leam/lang/git/makhidkarun/crewgen/cmd/crewgen as dir.
open /tmp/go-build3480032656/b001/data/human_male_first.txt: no such file or 
directory
open /tmp/go-build3480032656/b001/data/human_last.txt: no such file or directory
open /tmp/go-build3480032656/b001/data/human_female_first.txt: no such file or 
directory
open /tmp/go-build3480032656/b001/data/human_last.txt: no such file or directory
2022/02/25 04:48:27 open /tmp/go-build3480032656/b001/web/layout.tmpl: no such 
file or directory
--- FAIL: TestHandleDocroot (0.00s)
--- FAIL: TestHandleDocroot/BaseCrewgenRun (0.00s)
main_test.go:53: Response code is 500
###

It seems that identifying the /tmp/go-build* directory would be useful, in that 
I could write testdata files there and do better tests. Otherwise, building in 
a specified pre-existing location so I can make sure the data files are already 
in place.

Thoughts?

Leam



On 2/23/22 09:26, David Finkel wrote:



On Wed, Feb 23, 2022 at 8:53 AM Leam Hall mailto:leamh...@gmail.com>> wrote:

My program uses data and template files located relative to the binary. 
Since go test creates the binary under test in /tmp/go-build., there are no 
data or template files. How do I either specify what directory to build in so I 
can create the files, or get the tmp directory name before the tests are run so 
I can write files to it?


When go test runs tests, they run with the current working directory inside the 
package's directory, so relative paths should work.

Another option that you might want to consider is using //go:embed directives to 
embed those files in your binary. (package doc: https://pkg.go.dev/embed 
<https://pkg.go.dev/embed>)
This way you never need to resolve anything relative to the binary again.

Note: unless you use mlock(2) embedding in the binary shouldn't bloat memory 
usage, since the data will only be paged into memory at first-access.


Thanks!

Leam

-- 
Site Automation Engineer   (reuel.net/resume <http://reuel.net/resume>)

Scribe: The Domici War     (domiciwar.net <http://domiciwar.net>)
General Ne'er-do-well      (github.com/LeamHall 
<http://github.com/LeamHall>)

-- 
You received this message because you are subscribed to the Google Groups "golang-nuts" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com 
<mailto:golang-nuts%2bunsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7d8cf3dc-14ab-315f-ce5a-9e3cca877e17%40gmail.com
 
<https://groups.google.com/d/msgid/golang-nuts/7d8cf3dc-14ab-315f-ce5a-9e3cca877e17%40gmail.com>.



--
Site Automation Engineer   (reuel.net/resume)
Scribe: The Domici War (domiciwar.net)
General Ne'er-do-well  (github.com/LeamHall)

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/60b3e74a-13cb-b2f8-2c1f-18ef195ddee2%40gmail.com.


[go-nuts] Is there a way to specify or use the tmp directory used in testing?

2022-02-23 Thread Leam Hall

My program uses data and template files located relative to the binary. Since 
go test creates the binary under test in /tmp/go-build., there are no data 
or template files. How do I either specify what directory to build in so I can 
create the files, or get the tmp directory name before the tests are run so I 
can write files to it?

Thanks!

Leam

--
Site Automation Engineer   (reuel.net/resume)
Scribe: The Domici War (domiciwar.net)
General Ne'er-do-well  (github.com/LeamHall)

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7d8cf3dc-14ab-315f-ce5a-9e3cca877e17%40gmail.com.


Re: [go-nuts] some incorrect code in blog.

2021-11-24 Thread Leam Hall

On 11/24/21 20:26, Kurtis Rader wrote:

Notice the date of that blog article: 2010-08-04. It's more than eleven years 
old. Blog articles are not updated as the language changes.


It might be good to resolve that. If the authoritative info source for the 
language makes a habit of keeping old data up front, either update the material 
or quit posting stuff that ages to incorrectness. Winning a 2010 award ages 
well, code from 2010 might not. New community members don't need the hindrance, 
do they?

Leam

--
Systems Programmer (reuel.net/resume)
Scribe: The Domici War (domiciwar.net)
General Ne'er-do-well  (github.com/LeamHall)

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4711b003-719a-d2d9-ff09-6dabc6b2ce84%40gmail.com.


Re: [go-nuts] Re: Flag fall through logic review

2021-11-16 Thread Leam Hall

Brian, thanks! Here's the playground link:  
https://play.golang.org/p/Ef8D4CF-kKD

For the errors in lines 14-19, what other failures do you see needing to be handled? I'm 
still not comprehending how to check for "isReadable()", but that would be a 
useful next step. Of course, when the file is ingested there will need to be error 
checking there, too.

On lines 42-44, wouldn't the nil pointer issue be that the directory didn't 
exist? So far the code seems to handle that, but I'm probably missing a few 
things.

Leam

On 11/16/21 08:40, Brian Candler wrote:

(BTW, sharing your code on play.golang.org makes it easier to format and read)

On Tuesday, 16 November 2021 at 14:11:54 UTC leam...@gmail.com wrote:


14 func exists(filepath string) bool {
15 if _, err := os.Stat(filepath); errors.Is(err, fs.ErrNotExist) {
16 return false
17 }
18 return true
19 }


You are silently ignoring all errors here, apart from fs.ErrNotExist.  (You 
already identified that problem in your isDir function).

Basically there are three possible results: file exists, file doesn't exist, or 
something went wrong.  The traditional way to return that would be as a pair of 
values (bool, err)

Alternatively, it might be reasonable to panic(err) on any other non-nil error 
here.

42 if exists(*custom_datadir) {
43 customData = isDir(*custom_datadir)
44 }


Screams "pointer not checked for nil" to me.


--
Systems Programmer (reuel.net/resume)
Scribe: The Domici War (domiciwar.net)
General Ne'er-do-well  (github.com/LeamHall)

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/6af418b2-767c-435b-87e7-9ec09c82dd76%40gmail.com.


[go-nuts] Flag fall through logic review

2021-11-16 Thread Leam Hall

I'm re-learning Go and building a program to create characters for role-playing 
games. The program uses text files to build lists, and I'd like to let the user 
change the lists. For example, a modern day Earth game would only have human 
characters, but a Star Trek (TNG) game might have other species options, and a 
Star Wars game might have an even different set.

The logic is:
1. If run as provided, the program uses a default directory and default text 
files.
2. A user can modify one of the default text files to suit their needs.
3. A user can specify a custom directory for text files.
3.1. If a file of the same name as a default file exists in the custom 
directory, the
program will use the custom file.
3.2. If a custom file does not exist, the program will use the default.

How would you feel about that, as a user?
How can the code and logic be improved?

Thanks!

Leam

###
  1 // Package cli_fallthrough tests setting various vars.
  2
  3 package main
  4
  5 import (
  6 "errors"
  7 "flag"
  8 "fmt"
  9 "io/fs"
 10 "os"
 11 fp "path/filepath"
 12 )
 13
 14 func exists(filepath string) bool {
 15 if _, err := os.Stat(filepath); errors.Is(err, fs.ErrNotExist) {
 16 return false
 17 }
 18 return true
 19 }
 20
 21 func isDir(filepath string) bool {
 22 // Need better logic here. What to do if there is an err?
 23 dir, _ := os.Stat(filepath)
 24 if dir.IsDir() {
 25 return true
 26 }
 27 return false
 28 }
 29
 30 func main() {
 31 customData := false
 32 datadir := "data"
 33 datafiles := map[string]string{
 34 "species":   "species.txt",
 35 "conflicts": "conflicts.txt",
 36 "positives": "positives.txt",
 37 }
 38
 39 custom_datadir := flag.String("custom", "custom", "custom directory for 
data")
 40 flag.Parse()
 41
 42 if exists(*custom_datadir) {
 43 customData = isDir(*custom_datadir)
 44 }
 45
 46 for k, v := range datafiles {
 47 datafiles[k] = fp.Join(datadir, v)
 48 if customData {
 49 filepath := fp.Join(*custom_datadir, v)
 50 if exists(filepath) && !isDir(filepath) {
 51 datafiles[k] = filepath
 52 }
 53 }
 54 _, err := os.Stat(datafiles[k])
 55 if os.IsNotExist(err) {
 56 fmt.Println(err)
 57 }
 58 fmt.Printf("using %s.\n", datafiles[k])
 59 }
 60 }

###
--
Systems Programmer (reuel.net/resume)
Scribe: The Domici War (domiciwar.net)
General Ne'er-do-well  (github.com/LeamHall)

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/34b76275-638c-1f80-9e14-81ca6b57c7e0%40gmail.com.


Re: [go-nuts] Various questions about posts from The Go Blog

2021-11-08 Thread Leam Hall

I agree with Kamil. Go is young and growing. Committing to keeping at least the 
"official" blogs updated will help us on-board new gophers and get them 
productive quickly.

I appreciate the effort the Go team puts into the blogs and documents. How can 
we make it easier and better?

Leam

On 11/8/21 06:03, Kamil Ziemian wrote:

"Blog posts should really be viewed as a snapshot that is valid when they're 
published (that's why they contain a date)"
I agree, but since page that you are referring contains numbers of links to Go Blog posts with description 
"The official blog of the Go project , featuring news and in-depth 
articles by the Go team and guests.", I feel that they should put this disclaimer on this page or move 
links to posts to another page. "Using Go Module " is 
among posts linked on Documentation.

Maybe there is a way to suggest such a simple change to this page to people 
that maintain documentation? Or maybe this is over the top idea?

Best
Kamil

pon., 8 lis 2021 o 12:31 Sean Liao mailto:seankhl...@gmail.com>> napisał(a):

Blog posts should really be viewed as a snapshot that is valid when they're 
published (that's why they contain a date)
The guides under https://golang.org/doc/#getting-started 
 however should be kept up to date 
with the latest releases

On Monday, November 8, 2021 at 11:24:48 AM UTC+1 kziem...@gmail.com 
 wrote:

"Technically that behaviour is still available via GO111MODULE=auto.
Go 1.16 changed the default from "auto" to "on"."

Thank you for that information. It is surprisingly hard to me to learn 
basic of Go and Go tools, when things don't works as described.

I found few another places where "Using Go Modules" 
(https://go.dev/blog/using-go-modules ) is not up 
to date with out of box Go version 1.17.2.

1) According to part "Adding a dependency" (end of fourth block of text) 
"Only direct dependencies are recorded in the go.mod file". But my go.mod file contains 
lines.

require (
golang.org/x/text  
v0.0.0-20170915032832-14c0d48ead0c // indirect
rsc.io/sampler  v1.3.0 // indirect
)

2) After using "go get golang.org/x/text " command 
"go list -m all" I get one line more that in blog post

golang.org/x/tools  
v0.0.0-20180917221912-90fa682c2a6e

3) After function TestProverb(t *testing.T) is and running "go test" 
(I'm quite sure that when I did this few years ago, this was the command that I used) I 
get

hello.go:5:2: no required module provides package rsc.io/quote/v3 
; to add it:
     go get rsc.io/quote/v3 

This is easy to solve by running "go get rsc.io/quote/v3 
", but still annoying when you are going through this post.

Best
Kamil
niedziela, 31 października 2021 o 00:29:57 UTC+2 Kamil Ziemian 
napisał(a):

This is probably silly thing, but I will write it down just in case.

I mentioned before Go blog post "Using Go Modules" 
(https://go.dev/blog/using-go-modules ), we first 
write a function

func Hello() string {
     return "Hello, world."
}

and test for it which basically check condition

Hello() == "Hello, world."

In the next step we change our function to

func Hello() string {
     return quote.Hello()
}

using the module "rsc.io/quote ". But this is "not 
portable example" and when test on my computer PASS when using the first version of our Hello() 
function, it FAILS with the second.

According to description quote.Hello() (https://pkg.go.dev/rsc.io/quote#Hello 
), but from source code we know that in fact it returns 
a string returned by sampler.Hello(prefs ...language.Tag). The last function "returns a 
localized greeting. If no prefs are given, Hello uses DefaultUserPrefs." 
(https://pkg.go.dev/rsc.io/sampler#Hello ).

On my computer it correctly detected polish language so quote.Hello() returns "Witaj 
świecie." and since "Witaj świecie." != "Hello, world." the test now fails.

Best
Kamil

sob., 30 paź 2021 o 23:28 Sean Liao  napisał(a):

Technically that behaviour is still available via 
GO111MODULE=auto.
Go 1.16 changed the default from "auto" to "on".

On Saturday, October 30, 2021 at 11:17:05 PM UTC+2 
kziem...@gmail.com wrote:

   

[go-nuts] Go on AWS Lambda?

2021-11-02 Thread Leam Hall

I know Go can go on AWS Lambda, but I'm noob enough not to see how the memory 
performance value of Go translates to serverless. What are the benefits to 
using Go on AWS serverless?

Thanks!

Leam

--
Systems Programmer (reuel.net/resume)
Scribe: The Domici War (domiciwar.net)
General Ne'er-do-well  (github.com/LeamHall)

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/8d6691be-fa38-68e9-658d-aea14abcbe50%40gmail.com.


[go-nuts] Re: Best Go paid course

2021-10-23 Thread Leam Hall
Ahmed,

I would recommend two pairs of resources. First, if you want to build your 
level of Go above the basic, get "Learning Go" by Jon Bodner, and check out 
his Safaribooks Online "Go in 3 Hours" video. Once you're solid there, look 
at William "Bill" Kennedy's "Ultimate Go Course, 2nd edition" on 
Safaribooks Online. There is an "Ultimate Go notebook" that parallels the 
course.

Coursera has a specialization on Go, from UCB. That might interest you as 
well. If you did that, I would put it between Jon's book/course and Bill's. 
The UCB course is better if you have a decent introduction to the langauge 
before starting.

Leam

On Sunday, October 10, 2021 at 2:44:11 PM UTC-5 ahme...@gmail.com wrote:

> Hello friends,
> I'm an engineer with some good background in different programming 
> languages like dotnet and Spring boot, also I have focused on web (mainly 
> react) for the past few years, I also have `basic` knowledge in Go.
>
> Now i need to take the next level in Go and build some large scale API 
> application with multiple database backends and 3rd party API integration 
> (mostly rest). 
>
> So i'm thinking to buy a course that gives me the jumpstart, especially in 
> areas like concurrency and performance optimization, I would appreciate any 
> recommendation for a paid course and hope that such course already exists.
>
> Best,
> Ahmed
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/94894873-4082-4ccb-aeb6-733cc33e181en%40googlegroups.com.


[go-nuts] Both "Go+ Community" and "Go on Google+" pages on blog.golang.org are old

2017-05-30 Thread leam hall
One was last updated in 2015, the other in 2013. Am I missing more than my 
usual clue?

Leam

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.