Re: [go-nuts] Abridged summary of golang-nuts@googlegroups.com - 6 updates in 1 topic

2025-01-23 Thread Hugh Myrie
Hi there,

Thank you for the suggestions. I'll explore the Document AI as a potential
solution and will look into PDF to XML converters as well.

Best regards,
Hugh




On Thu, Jan 23, 2025, 4:35 PM  wrote:

> golang-nuts@googlegroups.com
> <https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/golang-nuts/topics>
>  Google
> Groups
> <https://groups.google.com/forum/?utm_source=digest&utm_medium=email/#!overview>
>  [image:
> Google Groups Logo]
> <https://groups.google.com/forum/?utm_source=digest&utm_medium=email/#!overview>
> Today's topic summary
> View all topics
> <https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/golang-nuts/topics>
>
>- PDF to text
><#m_-5809117193273972794_m_-1916359406536345700_group_thread_0> - 6
>Updates
>
> PDF to text
> <http://groups.google.com/group/golang-nuts/t/7fb689c074dc6704?utm_source=digest&utm_medium=email>
> Edgar Madrigal : Jan 22 01:44PM -0800
>
> The function extract
> https://pkg.go.dev/github.com/heussd/pdftotext-go#Extract actually says:
> Extract
> PDF text content in simplified format
> That might mean it will return text only and not ...more
> <http://groups.google.com/group/golang-nuts/msg/d4fb70cf8c828?utm_source=digest&utm_medium=email>
> Mike Schinkel : Jan 22 10:25PM -0500
>
> Hi Hugh,
>
> I have been planning to do some Go work with PDF files, so your email
> triggered me to do some research.
>
> Not sure it using heussd/pdftotext-go is critical to you, or if you are
> just ...more
> <http://groups.google.com/group/golang-nuts/msg/d5ef2741384a6?utm_source=digest&utm_medium=email>
> Hugh Myrie : Jan 23 07:29AM -0500
>
> Hi Mike,
>
> Thanks for the suggestion! I'm interested in checking out your forked code.
> It seems like a good alternative to what I'm currently using.
>
> Hugh
>
> ...more
> <http://groups.google.com/group/golang-nuts/msg/d7ca4045d1b88?utm_source=digest&utm_medium=email>
> Michael Bright : Jan 23 09:17AM -0800
>
> Hi Mike,
>
> Not wanting to suggest that you take the Python route, but just sharing my
> experience.
>
> I've tried Acrobat Reader's "Save as Text" functionality, and also one or
> two Python libraries ...more
> <http://groups.google.com/group/golang-nuts/msg/d6b9a60ac6069?utm_source=digest&utm_medium=email>
> robert engels : Jan 23 11:55AM -0600
>
> You typically can’t convert a PDF to text and do what you are trying to do.
>
> Look for PDF to XML converters - you need the “blocks” and the hierarchy
> in order to interpret most PDFs with any ...more
> <http://groups.google.com/group/golang-nuts/msg/d6bff07d434d2?utm_source=digest&utm_medium=email>
> Sharon Mafgaoker : Jan 23 08:56PM +0200
>
> Hey,
>
> I’m using
> https://cloud.google.com/document-ai
>
> I’m sending my pdf and getting back extracted text json object.
>
> Work fast and not expensive 🙏
>
> I hope this will help you .
> ...more
> <http://groups.google.com/group/golang-nuts/msg/d6f543da14d8c?utm_source=digest&utm_medium=email>
> Back to top <#m_-5809117193273972794_m_-1916359406536345700_digest_top>
> You received this digest because you're subscribed to updates for this
> group. You can change your settings on the group membership page
> <https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/golang-nuts/join>
> .
> To unsubscribe from this group and stop receiving emails from it send an
> email to golang-nuts+unsubscr...@googlegroups.com.
>

-- 
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 visit 
https://groups.google.com/d/msgid/golang-nuts/CAN-X3%3DZq7Cv0tb3%2B3C5WL72pqZnOERKK5dOi8%3DcuaFXU9TuxSA%40mail.gmail.com.


Re: [go-nuts] PDF to text

2025-01-23 Thread Hugh Myrie
Hi Michael,

You're absolutely right, PDF extraction can be a real headache!
I've tried Mike's suggestion, but unfortunately, it didn't quite work as
I'd hoped – it put each character on a separate line, which made it just as
difficult to work with.

I think I'll give OCR a shot and see if that yields better results. If that
doesn't pan out, I might explore some Python libraries, as you suggested.

Thanks again for your input, it's much appreciated!

Best regards,
Hugh


On Thu, Jan 23, 2025, 12:49 PM Michael Bright  wrote:

>
> Hi Mike,
>
> Not wanting to suggest that you take the Python route, but just sharing my
> experience.
>
> I've tried Acrobat Reader's "Save as Text" functionality, and also one or
> two Python libraries to extract text from PDFs (PyPDF2 is the one I've
> settled on).
>
> But what I learnt - without really digging into the issue - is that PDF is
> a pretty weird format where text from the same sentence/paragraph "floats
> around" as separate objects.
> Bottom line is -  no matter what tool you use - you may find it really
> tricky to get polished text from what seems like a simple PDF.
>
> That said ... please please prove me wrong !
> If anyone has a good pdf extraction tool in any easy to use form I'm
> interested.
>
> My own use case is to extract text from some partner training materials
> which I regularly deliver so that I can do a diff to see what changed
> between releases (obviously if they actually summarized that would be
> ideal, but they point me to pdfdiff ... yuk).
>
> I have some scripting that - just about - works but it's an absolute pain
> having
> - sentence/paragraphs broken up into multiple lines (and not the same
> across releases)
> - embedded code (in boxes) is indistinguishable from other text.
>
> My 2cts.py,
> another Mike.
>
>
> On Thursday, January 23, 2025 at 1:30:33 PM UTC+1 Hugh Myrie wrote:
>
> Hi Mike,
>
> Thanks for the suggestion! I'm interested in checking out your forked
> code. It seems like a good alternative to what I'm currently using.
>
> Hugh
>
> On Wed, Jan 22, 2025, 10:25 PM Mike Schinkel  wrote:
>
> Hi Hugh,
>
> I have been planning to do some Go work with PDF files, so your email
> triggered me to do some research.
>
> Not sure it using heussd/pdftotext-go is critical to you, or if you are
> just trying to read text in a PDF?  I tried to get pdf2text installed but
> my dev laptop is still running macOS Monterey and I couldn't get it working
> so I looked for other options.
>
> If you are just interested in reading PDF text and do not have a specific
> need to use pdf2text then one those others I looked at might work. I came
> across a package originally developed by Russ Cox that was forked by many
> others, and to evaluate it I forked one of those and then converted it from
> using a reader to returning a slice of strings so I could easily split out
> the new lines. (I could probably have make it work with the reader, but I
> was just going for quick.)
>
> If you think it can help your use-case, please check it out (but be aware,
> my additions to the forked code are rather hacky):
>
> https://github.com/mikeschinkel/go-pdf-content-reader
>
> -Mike
>
> On Jan 22, 2025, at 11:08 AM, Hugh Myrie  wrote:
>
> I want to extract text from a PDF and preserve any table or at least
> convert it to a CSV. I am using the PDFtoText package (which uses the
> Poppler software). The text is extracted vertically (i.e. one column at a
> time) and each text is separated by a space. There is no line break making
> it difficult to manipulate. I want to extract the text horizontally to
> preserve and possible add line breaks to allow for further manipulation.
>
> Your help in this matter is appreciated. Suggest alternatives if available.
>
> Here is the Go code:
>
> package main
>
> import (
> "fmt"
> "log"
> "os"
>
> pdftotext "github.com/heussd/pdftotext-go"
> )
>
> func main() {
> // Replace "test.pdf" with the path to your PDF file
> pdfPath := "test.pdf"
> // Open the PDF file
> f, err := os.Open(pdfPath)
> if err != nil {
> log.Fatalf("Failed to open PDF file: %v", err)
> }
> defer f.Close()
> // Read the file content
> content, err := os.ReadFile(pdfPath)
> if err != nil {
> log.Fatalf("Failed to read PDF file: %v", err)
> }
> // Extract text from the PDF file
> text, err := pdftotext.Extract(content)
> if err != nil {
> log.Fatalf("Faile

Re: [go-nuts] PDF to text

2025-01-23 Thread Hugh Myrie
Hi Mike,

Thanks for the suggestion! I'm interested in checking out your forked code.
It seems like a good alternative to what I'm currently using.

Hugh

On Wed, Jan 22, 2025, 10:25 PM Mike Schinkel  wrote:

> Hi Hugh,
>
> I have been planning to do some Go work with PDF files, so your email
> triggered me to do some research.
>
> Not sure it using heussd/pdftotext-go is critical to you, or if you are
> just trying to read text in a PDF?  I tried to get pdf2text installed but
> my dev laptop is still running macOS Monterey and I couldn't get it working
> so I looked for other options.
>
> If you are just interested in reading PDF text and do not have a specific
> need to use pdf2text then one those others I looked at might work. I came
> across a package originally developed by Russ Cox that was forked by many
> others, and to evaluate it I forked one of those and then converted it from
> using a reader to returning a slice of strings so I could easily split out
> the new lines. (I could probably have make it work with the reader, but I
> was just going for quick.)
>
> If you think it can help your use-case, please check it out (but be aware,
> my additions to the forked code are rather hacky):
>
> https://github.com/mikeschinkel/go-pdf-content-reader
>
> -Mike
>
> On Jan 22, 2025, at 11:08 AM, Hugh Myrie  wrote:
>
> I want to extract text from a PDF and preserve any table or at least
> convert it to a CSV. I am using the PDFtoText package (which uses the
> Poppler software). The text is extracted vertically (i.e. one column at a
> time) and each text is separated by a space. There is no line break making
> it difficult to manipulate. I want to extract the text horizontally to
> preserve and possible add line breaks to allow for further manipulation.
>
> Your help in this matter is appreciated. Suggest alternatives if available.
>
> Here is the Go code:
>
> package main
>
> import (
> "fmt"
> "log"
> "os"
>
> pdftotext "github.com/heussd/pdftotext-go"
> )
>
> func main() {
> // Replace "test.pdf" with the path to your PDF file
> pdfPath := "test.pdf"
> // Open the PDF file
> f, err := os.Open(pdfPath)
> if err != nil {
> log.Fatalf("Failed to open PDF file: %v", err)
> }
> defer f.Close()
> // Read the file content
> content, err := os.ReadFile(pdfPath)
> if err != nil {
> log.Fatalf("Failed to read PDF file: %v", err)
> }
> // Extract text from the PDF file
> text, err := pdftotext.Extract(content)
> if err != nil {
> log.Fatalf("Failed to extract text from PDF file: %v", err)
> }
> // Print the extracted text
> fmt.Println(text)
> }
>
>
> --
> 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 visit
> https://groups.google.com/d/msgid/golang-nuts/c19e212d-a81f-4525-ae0d-a9abb0b292fbn%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/c19e212d-a81f-4525-ae0d-a9abb0b292fbn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
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 visit 
https://groups.google.com/d/msgid/golang-nuts/CAN-X3%3DZEUgPfWbCvXzRB%2BuYYq2FqqvL8CD420TixSMLwEv6d3g%40mail.gmail.com.


[go-nuts] PDF to text

2025-01-22 Thread Hugh Myrie
I want to extract text from a PDF and preserve any table or at least 
convert it to a CSV. I am using the PDFtoText package (which uses the 
Poppler software). The text is extracted vertically (i.e. one column at a 
time) and each text is separated by a space. There is no line break making 
it difficult to manipulate. I want to extract the text horizontally to 
preserve and possible add line breaks to allow for further manipulation.

Your help in this matter is appreciated. Suggest alternatives if available.

Here is the Go code:

package main

import (
"fmt"
"log"
"os"

pdftotext "github.com/heussd/pdftotext-go"
)

func main() {
// Replace "test.pdf" with the path to your PDF file
pdfPath := "test.pdf"
// Open the PDF file
f, err := os.Open(pdfPath)
if err != nil {
log.Fatalf("Failed to open PDF file: %v", err)
}
defer f.Close()
// Read the file content
content, err := os.ReadFile(pdfPath)
if err != nil {
log.Fatalf("Failed to read PDF file: %v", err)
}
// Extract text from the PDF file
text, err := pdftotext.Extract(content)
if err != nil {
log.Fatalf("Failed to extract text from PDF file: %v", err)
}
// Print the extracted text
fmt.Println(text)
}

-- 
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 visit 
https://groups.google.com/d/msgid/golang-nuts/c19e212d-a81f-4525-ae0d-a9abb0b292fbn%40googlegroups.com.


Re: [go-nuts] Preserving special characters when reading Go POST request body

2024-07-03 Thread Hugh Myrie
Look at the sample text file and tell why the special characters differ.

When I open the file in VSCode, the special characters in the first sample 
are highlighted.

Could you explain why?

On Wednesday, July 3, 2024 at 10:42:07 AM UTC-4 Hugh Myrie wrote:

> Yes, PeterGo got it correctly. That is what I expect to see so I can post 
> it to an API.
>
> On Tuesday, July 2, 2024 at 11:28:39 PM UTC-4 peterGo wrote:
>
>> Ian,
>>
>> Hugh Myrie might be expecting to see something like this:
>>
>> https://go.dev/play/p/7TlD5R1C0oX
>>
>> Peter
>>
>> On Tuesday, July 2, 2024 at 9:53:41 PM UTC-4 Ian Lance Taylor wrote:
>>
>> On Tue, Jul 2, 2024 at 5:29 PM Hugh Myrie  wrote:
>>
>> When I change the %s to %q in the print function I see the special 
>> characters in their Hexadecimal representations.
>>
>> See below:
>>
>> 0011020240702\x1d0201758001030085245467021.00Y50072 
>> 202407020\x1cDG\x1cDI00\x1cE7\x1cG1200   
>> \x1cG2X \x1cG310\x1cG4E79   \x03
>>
>>
>> I am using the original code (JSON).
>>
>> How do I then change them back to the actual characters?
>>
>>
>> If you see the characters with %q, then they are also there with %s.  But 
>> since they aren't printable characters, you aren't seeing them.
>>
>> To put it another way: what do you expect to see?
>>
>> Ian
>>
>>
>>  
>>
>> On Tuesday, July 2, 2024 at 7:15:36 PM UTC-4 Ian Lance Taylor wrote:
>>
>> 1) Please send Go code as plain text, not as an image.  Anybody can read 
>> plain text.  Images are hard to read.  Thanks.
>>
>> 2) What do you see if you change the %s to %q in the fmt.Printf call?
>>
>> Ian
>>
>> On Tue, Jul 2, 2024 at 3:40 PM Hugh Myrie  wrote:
>>
>> The original Go function is shown below. Initially, a JSON-encoded string 
>> is sent from the client. The first print function is used to view the 
>> output after decoding.
>>
>>
>> func SendClaim(w http.ResponseWriter, r *http.Request) {
>> //  strEcho := "Halo"
>> servAddr := tcpAddress
>>
>> type Resp struct {
>> Status string `json:"status"`
>> Reply  string `json:"reply"`
>> }
>> type Claim struct {
>> ClaimInfo string `json:"claiminfo"`
>> }
>>
>> var params Claim
>>
>> erx := json.NewDecoder(r.Body).Decode(¶ms)
>> if erx != nil {
>> http.Error(w, erx.Error(), http.StatusBadRequest)
>> fmt.Println("Error occurs here")
>> log.Printf(erx.Error())
>> return
>> }
>> fmt.Printf("Claims: %s \n", params)
>> //  policy := params.CardNo //r.FormValue("cardno")
>> //  log.Println("policy # ", policy)
>>
>> tcpAddr, err := net.ResolveTCPAddr("tcp", servAddr)
>> if err != nil {
>> println("ResolveTCPAddr failed:", err.Error())
>> respondWithError(w, http.StatusBadRequest, err.Error())
>> return
>> }
>>
>> data := params.ClaimInfo
>> //  printr := r.FormValue("printer")
>>
>> fmt.Println(data)
>> conn, err := net.DialTCP("tcp", nil, tcpAddr)
>> if err != nil {
>> println("Dial failed:", err.Error())
>> respondWithError(w, http.StatusBadRequest, err.Error())
>> return
>> }
>>
>>     _, err = conn.Write([]byte(data))
>> if err != nil {
>> println("Write to server failed:", err.Error())
>> respondWithError(w, http.StatusBadRequest, err.Error())
>> return
>> }
>>
>> reply := make([]byte, 1024)
>>
>> _, err = conn.Read(reply)
>> if err != nil {
>> println("Write to server failed:", err.Error())
>> respondWithError(w, http.StatusBadRequest, err.Error())
>> return
>> }
>>
>> resp := Resp{}
>> println("reply from server=", string(reply))
>> resp.Status = "response"
>> resp.Reply = string(reply)
>>
>> respondWithJSON(w, http.StatusOK, resp)
>>
>> conn.Close()
>> }
>>
>>
>> On Tuesday, July 2, 2024 at 9:28:01 AM UTC-4 Hugh Myrie wrote:
>>
>> Copying the result to notepad confirms the missing special characters.. 
>>
>> I'll

Re: [go-nuts] Preserving special characters when reading Go POST request body

2024-07-03 Thread Hugh Myrie
Yes, PeterGo got it correctly. That is what I expect to see so I can post 
it to an API.

On Tuesday, July 2, 2024 at 11:28:39 PM UTC-4 peterGo wrote:

> Ian,
>
> Hugh Myrie might be expecting to see something like this:
>
> https://go.dev/play/p/7TlD5R1C0oX
>
> Peter
>
> On Tuesday, July 2, 2024 at 9:53:41 PM UTC-4 Ian Lance Taylor wrote:
>
> On Tue, Jul 2, 2024 at 5:29 PM Hugh Myrie  wrote:
>
> When I change the %s to %q in the print function I see the special 
> characters in their Hexadecimal representations.
>
> See below:
>
> 0011020240702\x1d0201758001030085245467021.00Y50072 
> 202407020\x1cDG\x1cDI00\x1cE7\x1cG1200   
> \x1cG2X \x1cG310\x1cG4E79   \x03
>
>
> I am using the original code (JSON).
>
> How do I then change them back to the actual characters?
>
>
> If you see the characters with %q, then they are also there with %s.  But 
> since they aren't printable characters, you aren't seeing them.
>
> To put it another way: what do you expect to see?
>
> Ian
>
>
>  
>
> On Tuesday, July 2, 2024 at 7:15:36 PM UTC-4 Ian Lance Taylor wrote:
>
> 1) Please send Go code as plain text, not as an image.  Anybody can read 
> plain text.  Images are hard to read.  Thanks.
>
> 2) What do you see if you change the %s to %q in the fmt.Printf call?
>
> Ian
>
> On Tue, Jul 2, 2024 at 3:40 PM Hugh Myrie  wrote:
>
> The original Go function is shown below. Initially, a JSON-encoded string 
> is sent from the client. The first print function is used to view the 
> output after decoding.
>
>
> func SendClaim(w http.ResponseWriter, r *http.Request) {
> //  strEcho := "Halo"
> servAddr := tcpAddress
>
> type Resp struct {
> Status string `json:"status"`
> Reply  string `json:"reply"`
> }
> type Claim struct {
> ClaimInfo string `json:"claiminfo"`
> }
>
> var params Claim
>
> erx := json.NewDecoder(r.Body).Decode(¶ms)
> if erx != nil {
> http.Error(w, erx.Error(), http.StatusBadRequest)
> fmt.Println("Error occurs here")
> log.Printf(erx.Error())
> return
> }
> fmt.Printf("Claims: %s \n", params)
> //  policy := params.CardNo //r.FormValue("cardno")
> //  log.Println("policy # ", policy)
>
> tcpAddr, err := net.ResolveTCPAddr("tcp", servAddr)
> if err != nil {
> println("ResolveTCPAddr failed:", err.Error())
> respondWithError(w, http.StatusBadRequest, err.Error())
> return
> }
>
> data := params.ClaimInfo
> //  printr := r.FormValue("printer")
>
> fmt.Println(data)
> conn, err := net.DialTCP("tcp", nil, tcpAddr)
> if err != nil {
> println("Dial failed:", err.Error())
> respondWithError(w, http.StatusBadRequest, err.Error())
> return
> }
>
> _, err = conn.Write([]byte(data))
> if err != nil {
> println("Write to server failed:", err.Error())
> respondWithError(w, http.StatusBadRequest, err.Error())
> return
> }
>
> reply := make([]byte, 1024)
>
> _, err = conn.Read(reply)
> if err != nil {
> println("Write to server failed:", err.Error())
> respondWithError(w, http.StatusBadRequest, err.Error())
> return
> }
>
> resp := Resp{}
> println("reply from server=", string(reply))
> resp.Status = "response"
> resp.Reply = string(reply)
>
> respondWithJSON(w, http.StatusOK, resp)
>
> conn.Close()
> }
>
>
> On Tuesday, July 2, 2024 at 9:28:01 AM UTC-4 Hugh Myrie wrote:
>
> Copying the result to notepad confirms the missing special characters.. 
>
> I'll try your suggestion.
>
> Thanks.
>
>
> <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
> Virus-free.www.avg.com 
> <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
>  
> <#m_-8200846656951506443_m_6273277082335633664_m_-4475757952619024099_m_7810203444138361032_m_3329966587656473292_m_4334311486301273828_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> On Tue, Jul 2, 2024 at 8:33 AM 'Dan Kortschak' via golang-nuts <
> golan...@googlegroups.com> wrote:
>
> On Mon, 2024-07-01 at 12:03 -0700, Hugh Myrie wrote:
> > I am trying to preserve special characters (group

Re: [go-nuts] Preserving special characters when reading Go POST request body

2024-07-02 Thread Hugh Myrie
Go code as plain text below:

unc SendClaim(w http.ResponseWriter, r *http.Request) {
//  strEcho := "Halo"
servAddr := tcpAddress

type Resp struct {
Status string `json:"status"`
Reply  string `json:"reply"`
}
type Claim struct {
ClaimInfo string `json:"claiminfo"`
}

var params Claim

erx := json.NewDecoder(r.Body).Decode(¶ms)
if erx != nil {
http.Error(w, erx.Error(), http.StatusBadRequest)
fmt.Println("Error occurs here")
log.Printf(erx.Error())
return
}
fmt.Printf("Claims: %s", params)
// policy := params.CardNo //r.FormValue("cardno")
// log.Println("policy # ", policy)

tcpAddr, err := net.ResolveTCPAddr("tcp", servAddr)
if err != nil {
println("ResolveTCPAddr failed:", err.Error())
respondWithError(w, http.StatusBadRequest, err.Error())
return
}

data := params.ClaimInfo
// printr := r.FormValue("printer")

fmt.Println(data)
conn, err := net.DialTCP("tcp", nil, tcpAddr)
if err != nil {
println("Dial failed:", err.Error())
respondWithError(w, http.StatusBadRequest, err.Error())
return
}

_, err = conn.Write([]byte(data))
if err != nil {
println("Write to server failed:", err.Error())
respondWithError(w, http.StatusBadRequest, err.Error())
return
}

reply := make([]byte, 1024)

_, err = conn.Read(reply)
if err != nil {
println("Write to server failed:", err.Error())
respondWithError(w, http.StatusBadRequest, err.Error())
return
}

resp := Resp{}
println("reply from server=", string(reply))
resp.Status = "response"
resp.Reply = string(reply)

respondWithJSON(w, http.StatusOK, resp)

conn.Close()
}

On Tuesday, July 2, 2024 at 8:28:54 PM UTC-4 Hugh Myrie wrote:

> When I change the %s to %q in the print function I see the special 
> characters in their Hexadecimal representations.
>
> See below:
>
> 0011020240702\x1d0201758001030085245467021.00Y50072 
> 202407020\x1cDG\x1cDI00\x1cE7\x1cG1200   
> \x1cG2X \x1cG310\x1cG4E79   \x03
>
>
> I am using the original code (JSON).
>
> How do I then change them back to the actual characters?
>
> On Tuesday, July 2, 2024 at 7:15:36 PM UTC-4 Ian Lance Taylor wrote:
>
>> 1) Please send Go code as plain text, not as an image.  Anybody can read 
>> plain text.  Images are hard to read.  Thanks.
>>
>> 2) What do you see if you change the %s to %q in the fmt.Printf call?
>>
>> Ian
>>
>> On Tue, Jul 2, 2024 at 3:40 PM Hugh Myrie  wrote:
>>
>>> The original Go function is shown below. Initially, a JSON-encoded 
>>> string is sent from the client. The first print function is used to view 
>>> the output after decoding.
>>>
>>>
>>> func SendClaim(w http.ResponseWriter, r *http.Request) {
>>> //  strEcho := "Halo"
>>> servAddr := tcpAddress
>>>
>>> type Resp struct {
>>> Status string `json:"status"`
>>> Reply  string `json:"reply"`
>>> }
>>> type Claim struct {
>>> ClaimInfo string `json:"claiminfo"`
>>> }
>>>
>>> var params Claim
>>>
>>> erx := json.NewDecoder(r.Body).Decode(¶ms)
>>> if erx != nil {
>>> http.Error(w, erx.Error(), http.StatusBadRequest)
>>> fmt.Println("Error occurs here")
>>> log.Printf(erx.Error())
>>> return
>>> }
>>> fmt.Printf("Claims: %s \n", params)
>>> //  policy := params.CardNo //r.FormValue("cardno")
>>> //  log.Println("policy # ", policy)
>>>
>>> tcpAddr, err := net.ResolveTCPAddr("tcp", servAddr)
>>> if err != nil {
>>> println("ResolveTCPAddr failed:", err.Error())
>>> respondWithError(w, http.StatusBadRequest, err.Error())
>>> return
>>> }
>>>
>>> data := params.ClaimInfo
>>> //  printr := r.FormValue("printer")
>>>
>>> fmt.Println(data)
>>> conn, err := net.DialTCP("tcp", nil, tcpAddr)
>>> if err != nil {
>>> println("Dial failed:", err.Error())
>>> respondWithError(w, http.StatusBadRequest, err.Error())
>>> return
>>> }
>>>
>>> _, err = conn.Write([]byte(data))
>>> if err != nil {
>>> println("Write to server failed:", err.Error())
>>> respondWithError(w, http.StatusBadRequest, err.Error())
>>> ret

Re: [go-nuts] Preserving special characters when reading Go POST request body

2024-07-02 Thread Hugh Myrie
When I change the %s to %q in the print function I see the special 
characters in their Hexadecimal representations.

See below:

0011020240702\x1d0201758001030085245467021.00Y50072 
202407020\x1cDG\x1cDI00\x1cE7\x1cG1200   
\x1cG2X \x1cG310\x1cG4E79   \x03


I am using the original code (JSON).

How do I then change them back to the actual characters?

On Tuesday, July 2, 2024 at 7:15:36 PM UTC-4 Ian Lance Taylor wrote:

> 1) Please send Go code as plain text, not as an image.  Anybody can read 
> plain text.  Images are hard to read.  Thanks.
>
> 2) What do you see if you change the %s to %q in the fmt.Printf call?
>
> Ian
>
> On Tue, Jul 2, 2024 at 3:40 PM Hugh Myrie  wrote:
>
>> The original Go function is shown below. Initially, a JSON-encoded string 
>> is sent from the client. The first print function is used to view the 
>> output after decoding.
>>
>>
>> func SendClaim(w http.ResponseWriter, r *http.Request) {
>> //  strEcho := "Halo"
>> servAddr := tcpAddress
>>
>> type Resp struct {
>> Status string `json:"status"`
>> Reply  string `json:"reply"`
>> }
>> type Claim struct {
>> ClaimInfo string `json:"claiminfo"`
>> }
>>
>> var params Claim
>>
>> erx := json.NewDecoder(r.Body).Decode(¶ms)
>> if erx != nil {
>> http.Error(w, erx.Error(), http.StatusBadRequest)
>> fmt.Println("Error occurs here")
>> log.Printf(erx.Error())
>> return
>> }
>> fmt.Printf("Claims: %s \n", params)
>> //  policy := params.CardNo //r.FormValue("cardno")
>> //  log.Println("policy # ", policy)
>>
>> tcpAddr, err := net.ResolveTCPAddr("tcp", servAddr)
>> if err != nil {
>> println("ResolveTCPAddr failed:", err.Error())
>> respondWithError(w, http.StatusBadRequest, err.Error())
>> return
>> }
>>
>> data := params.ClaimInfo
>> //  printr := r.FormValue("printer")
>>
>> fmt.Println(data)
>> conn, err := net.DialTCP("tcp", nil, tcpAddr)
>> if err != nil {
>> println("Dial failed:", err.Error())
>> respondWithError(w, http.StatusBadRequest, err.Error())
>> return
>> }
>>
>> _, err = conn.Write([]byte(data))
>> if err != nil {
>> println("Write to server failed:", err.Error())
>> respondWithError(w, http.StatusBadRequest, err.Error())
>> return
>> }
>>
>> reply := make([]byte, 1024)
>>
>> _, err = conn.Read(reply)
>> if err != nil {
>> println("Write to server failed:", err.Error())
>> respondWithError(w, http.StatusBadRequest, err.Error())
>> return
>> }
>>
>> resp := Resp{}
>> println("reply from server=", string(reply))
>> resp.Status = "response"
>> resp.Reply = string(reply)
>>
>> respondWithJSON(w, http.StatusOK, resp)
>>
>> conn.Close()
>> }
>>
>>
>> On Tuesday, July 2, 2024 at 9:28:01 AM UTC-4 Hugh Myrie wrote:
>>
>>> Copying the result to notepad confirms the missing special characters.. 
>>>
>>> I'll try your suggestion.
>>>
>>> Thanks.
>>>
>>>
>>> <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
>>>  
>>> Virus-free.www.avg.com 
>>> <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
>>>  
>>> <#m_7810203444138361032_m_3329966587656473292_m_4334311486301273828_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>>
>>> On Tue, Jul 2, 2024 at 8:33 AM 'Dan Kortschak' via golang-nuts <
>>> golan...@googlegroups.com> wrote:
>>>
>>>> On Mon, 2024-07-01 at 12:03 -0700, Hugh Myrie wrote:
>>>> > I am trying to preserve special characters (group separators and
>>>> > field separators) when reading the request body from a POST request.
>>>> > 
>>>> > When I do a dumpRequest I am able to see the special characters (Hex
>>>> > Format, for example: \x1c or \x03). I am sending the data from the
>>>> > client as text/plain.
>>

Re: [go-nuts] Preserving special characters when reading Go POST request body

2024-07-02 Thread Hugh Myrie
The original Go function is shown below. Initially, a JSON-encoded string 
is sent from the client. The first print function is used to view the 
output after decoding.


func SendClaim(w http.ResponseWriter, r *http.Request) {
//  strEcho := "Halo"
servAddr := tcpAddress

type Resp struct {
Status string `json:"status"`
Reply  string `json:"reply"`
}
type Claim struct {
ClaimInfo string `json:"claiminfo"`
}

var params Claim

erx := json.NewDecoder(r.Body).Decode(¶ms)
if erx != nil {
http.Error(w, erx.Error(), http.StatusBadRequest)
fmt.Println("Error occurs here")
log.Printf(erx.Error())
return
}
fmt.Printf("Claims: %s \n", params)
//  policy := params.CardNo //r.FormValue("cardno")
//  log.Println("policy # ", policy)

tcpAddr, err := net.ResolveTCPAddr("tcp", servAddr)
if err != nil {
println("ResolveTCPAddr failed:", err.Error())
respondWithError(w, http.StatusBadRequest, err.Error())
return
}

data := params.ClaimInfo
//  printr := r.FormValue("printer")

fmt.Println(data)
conn, err := net.DialTCP("tcp", nil, tcpAddr)
if err != nil {
println("Dial failed:", err.Error())
respondWithError(w, http.StatusBadRequest, err.Error())
return
}

_, err = conn.Write([]byte(data))
if err != nil {
println("Write to server failed:", err.Error())
respondWithError(w, http.StatusBadRequest, err.Error())
return
}

reply := make([]byte, 1024)

_, err = conn.Read(reply)
if err != nil {
println("Write to server failed:", err.Error())
respondWithError(w, http.StatusBadRequest, err.Error())
return
}

resp := Resp{}
println("reply from server=", string(reply))
resp.Status = "response"
resp.Reply = string(reply)

respondWithJSON(w, http.StatusOK, resp)

conn.Close()
}


On Tuesday, July 2, 2024 at 9:28:01 AM UTC-4 Hugh Myrie wrote:

> Copying the result to notepad confirms the missing special characters.. 
>
> I'll try your suggestion.
>
> Thanks.
>
>
> <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
>  
> Virus-free.www.avg.com 
> <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
>  
> <#m_4334311486301273828_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> On Tue, Jul 2, 2024 at 8:33 AM 'Dan Kortschak' via golang-nuts <
> golan...@googlegroups.com> wrote:
>
>> On Mon, 2024-07-01 at 12:03 -0700, Hugh Myrie wrote:
>> > I am trying to preserve special characters (group separators and
>> > field separators) when reading the request body from a POST request.
>> > 
>> > When I do a dumpRequest I am able to see the special characters (Hex
>> > Format, for example: \x1c or \x03). I am sending the data from the
>> > client as text/plain.
>> > 
>> > I have tried sending the data as JSON and using the decoder in Go. I
>> > have also tried using Base64 and decoding in go accordingly. I have
>> > tried json.unmarshal to decode the incoming JSON data. However, in
>> > every instance the special characters are removed.
>> > 
>> > I need the special characters to be preserved so I can send the data
>> > for further processing. I need the special characters not the
>> > hexadecimal representation.
>> > 
>> > I am able to see the actual data being sent to the Go server. I also
>> > tried encoding the data from the client side.
>> > 
>> > Your help would be greatly appreciated.
>>
>> This looks to be working as expected. https://go.dev/play/p/fqLPbsMKaOm
>>
>> How are you seeing the bytes being missing?
>>
>>
>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "golang-nuts" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/golang-nuts/8cLWTdxHQCI/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> golang-nuts...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/9cf1e4d31b68f7601839a450e1a9aa572458e756.camel%40kortschak.io
>> .
>>
>
>
> -- 
> http://www.jaxtr.com/blessed_hope
>

-- 
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/6fd2520e-a7e3-43ed-89d5-dc96419d8a89n%40googlegroups.com.


Re: [go-nuts] Preserving special characters when reading Go POST request body

2024-07-02 Thread Hugh Myrie
Copying the result to notepad confirms the missing special characters..

I'll try your suggestion.

Thanks.

<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Virus-free.www.avg.com
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Tue, Jul 2, 2024 at 8:33 AM 'Dan Kortschak' via golang-nuts <
golang-nuts@googlegroups.com> wrote:

> On Mon, 2024-07-01 at 12:03 -0700, Hugh Myrie wrote:
> > I am trying to preserve special characters (group separators and
> > field separators) when reading the request body from a POST request.
> >
> > When I do a dumpRequest I am able to see the special characters (Hex
> > Format, for example: \x1c or \x03). I am sending the data from the
> > client as text/plain.
> >
> > I have tried sending the data as JSON and using the decoder in Go. I
> > have also tried using Base64 and decoding in go accordingly. I have
> > tried json.unmarshal to decode the incoming JSON data. However, in
> > every instance the special characters are removed.
> >
> > I need the special characters to be preserved so I can send the data
> > for further processing. I need the special characters not the
> > hexadecimal representation.
> >
> > I am able to see the actual data being sent to the Go server. I also
> > tried encoding the data from the client side.
> >
> > Your help would be greatly appreciated.
>
> This looks to be working as expected. https://go.dev/play/p/fqLPbsMKaOm
>
> How are you seeing the bytes being missing?
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/8cLWTdxHQCI/unsubscribe.
> To unsubscribe from this group and all its topics, 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/9cf1e4d31b68f7601839a450e1a9aa572458e756.camel%40kortschak.io
> .
>


-- 
http://www.jaxtr.com/blessed_hope

-- 
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/CAN-X3%3DZtCpnBMd2Tqr4ohfXRq-xSNH6ij-X%3DXsyjp%3DFy%2Bh1LZA%40mail.gmail.com.


[go-nuts] Preserving special characters when reading Go POST request body

2024-07-01 Thread Hugh Myrie
I am trying to preserve special characters (group separators and field 
separators) when reading the request body from a POST request.

When I do a dumpRequest I am able to see the special characters (Hex 
Format, for example: \x1c or \x03). I am sending the data from the client 
as text/plain.

I have tried sending the data as JSON and using the decoder in Go. I have 
also tried using Base64 and decoding in go accordingly. I have tried 
json.unmarshal to decode the incoming JSON data. However, in every instance 
the special characters are removed.

I need the special characters to be preserved so I can send the data for 
further processing. I need the special characters not the hexadecimal 
representation.

I am able to see the actual data being sent to the Go server. I also tried 
encoding the data from the client side.

Your help would be greatly appreciated.

-- 
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/6866b137-3606-45b1-9feb-67cf00d4a71en%40googlegroups.com.


Re: [go-nuts] ListenAndServeTLS() (pem and key files for private network)

2022-06-30 Thread Hugh Myrie
Martin, all the information is helpful as I am provided with possible
options. I am new to the SSL/TLS encryption process, so my question may not
be clearly stated. Yes it is a private network but I want
a secure network.and without the browser complaining that the certificate
is invalid, The option that you prescribe is important should the IP
address or DNS name of the server be changed. Based on the comments,
certificates are the accepted security standard. I am still open to
feedback.

On Thu, Jun 30, 2022 at 12:29 PM Robert Engels 
wrote:

> One great aspect of the certificates is that they can be revoked - so
> simply revoking a certificate will disable access across the board.
> Certificates are also supported by HSM and the like. It can simplify and
> secure the systems according to accepted security standards a bit more
> straightforward in my opinion.
>
> Passwords are going away…
>
> > On Jun 30, 2022, at 11:55 AM, Martin Schnabel  wrote:
> >
> > Sorry, i may have misunderstood the private network part, hope my
> answer was helpful anyway. My usecase was a local area network without a
> fixed ip or dns names, like common home network appliances. I thought about
> using client certificates too, but decided it would be easier to use common
> session cookie based password authentication over the tls connection.
> >
> > But now i am interested if i am missing something. What would be the
> reason to use client certificates instead?
> >
> >> On 6/30/22 16:29, Hugh Myrie wrote:
> >> Your help is much appreciated. Security is of paramount importance so I
> must take everything into consideration. I am learning so feel free to
> provide useful feedback.
> >> On Thu, Jun 30, 2022 at 7:22 AM Robert Engels  <mailto:reng...@ix.netcom.com>> wrote:
> >>I don’t think it needs to be that complicated just load the client
> >>public certs into the server. Validate upon usage that the cert is
> >>still valid. Easy to authenticate clients this way. This is how ssh
> >>works with certificate based authentication. Peer to peer is a
> >>little harder but usually you get the valid certs from a trusted
> >>server.
> >> > On Jun 30, 2022, at 6:35 AM, Konstantin Khomoutov
> >>mailto:kos...@bswap.ru>> wrote:
> >> >
> >> > On Mon, Jun 27, 2022 at 05:35:38PM -0700, Hugh Myrie wrote:
> >> >
> >> >> I wish to create a secure private network using a self-signed
> >>certificate
> >> >> with a Go web server: See the following code block:
> >> >>
> >> >> // Code
> >> >>err := http.ListenAndServeTLS(":"+port, "auto.org.pem",
> >> >> "auto.org-key.pem", handler)
> >> >>if err != nil {
> >> >>
> >> >>logError((err.Error()))
> >> >>log.Fatal("ListenAndServe: ", err)
> >> >>}
> >> >> // End of Code
> >> >>
> >> >> Could I auto  generate (and register) the .pem and .key files
> >>using GO?  I
> >> >> wish to create a trust certificate if there files do not exist.
> >> >>
> >> >> I came across the following website:
> >> >>
> >> >>
> >>"https://gist.github.com/shaneutt/5e1995295cff6721c89a71d13a71c251
> >><https://gist.github.com/shaneutt/5e1995295cff6721c89a71d13a71c251>"
> >> >>
> >> >> I am not sure how to implement this. Your help is appreciated.
> >> >
> >> > I'm afraid there may be a critical flaw in your approach as a
> >>concept.
> >> > I'll try to explain how I perceive it. I might be wrong in my
> >>assessment, and
> >> > if yes, please excuse me - I'm just trying to help.
> >> >
> >> > OK, so, TLS has two conceptual facets in the way it implements
> >>secure data
> >> > exchange tunnels: encryption (information hiding) and mutual
> >>authentication.
> >> > Based on my experience, people tend to ignore the second one
> >>while fixating on
> >> > the former. Maybe this comes from the extensive usage of web
> >>browsers, in
> >> > which using of certificates for authentication most of the time
> >>is strictly
> >> > one-way - most websites to not r

Re: [go-nuts] ListenAndServeTLS() (pem and key files for private network)

2022-06-30 Thread Hugh Myrie
Your help is much appreciated. Security is of paramount importance so I
must take everything into consideration. I am learning so feel free to
provide useful feedback.

On Thu, Jun 30, 2022 at 7:22 AM Robert Engels  wrote:

> I don’t think it needs to be that complicated just load the client public
> certs into the server. Validate upon usage that the cert is still valid.
> Easy to authenticate clients this way. This is how ssh works with
> certificate based authentication. Peer to peer is a little harder but
> usually you get the valid certs from a trusted server.
>
> > On Jun 30, 2022, at 6:35 AM, Konstantin Khomoutov 
> wrote:
> >
> > On Mon, Jun 27, 2022 at 05:35:38PM -0700, Hugh Myrie wrote:
> >
> >> I wish to create a secure private network using a self-signed
> certificate
> >> with a Go web server: See the following code block:
> >>
> >> // Code
> >>err := http.ListenAndServeTLS(":"+port, "auto.org.pem",
> >> "auto.org-key.pem", handler)
> >>if err != nil {
> >>
> >>logError((err.Error()))
> >>log.Fatal("ListenAndServe: ", err)
> >>}
> >> // End of Code
> >>
> >> Could I auto  generate (and register) the .pem and .key files using
> GO?  I
> >> wish to create a trust certificate if there files do not exist.
> >>
> >> I came across the following website:
> >>
> >> "https://gist.github.com/shaneutt/5e1995295cff6721c89a71d13a71c251";
> >>
> >> I am not sure how to implement this. Your help is appreciated.
> >
> > I'm afraid there may be a critical flaw in your approach as a concept.
> > I'll try to explain how I perceive it. I might be wrong in my
> assessment, and
> > if yes, please excuse me - I'm just trying to help.
> >
> > OK, so, TLS has two conceptual facets in the way it implements secure
> data
> > exchange tunnels: encryption (information hiding) and mutual
> authentication.
> > Based on my experience, people tend to ignore the second one while
> fixating on
> > the former. Maybe this comes from the extensive usage of web browsers, in
> > which using of certificates for authentication most of the time is
> strictly
> > one-way - most websites to not require their clients to authenticate on
> the
> > TLS level, and authenticating of the websites is well hidden under the
> hood.
> >
> > Now consider implementing a custom "secure private network" with the
> help of
> > TLS. Say, your server accepts TLS sessions from its clients, and uses
> > a self-signed certificate and the matching key. Now, have you thought
> out how
> > this server will make sure that a client wanting to connect to actually
> has
> > the permission to do that? Conversely, how the client knows the server is
> > legitimate and was not spoofed using a Man-in-the-Middle attack?
> >
> > To authenticate clients, you might implement some non-TLS method - such
> as
> > passwords. This would work, but when architecting a secure communication
> > system you should apply "security mindset" when thinking: if the client
> has
> > set up a TLS session with a rogue server, any information the client
> sends to
> > that session must be considered as compromised, and any imformation
> received
> > must not be trusted (unless there's a way to reliably verify it). This
> inclues
> > the password exchange. You could implement a secure password exchange
> scheme
> > which does not result in disclosing the password (only proves its
> knowledge)
> > but the rogue server can just tell the client it authenticated OK, and
> then
> > start accepting actual data from the client. You could implement the
> reverse
> > scheme to also authenticate the server to the client, and this would
> require
> > keeping the server's password on each client.
> >
> > OK, so TLS is already able to authenticate both sides to each other -
> using
> > certificates. There are two ways do do it. The "normal" one is to trust a
> > certificate presented during a TLS handshake exchange by trusting
> whoever had
> > issued that certificate (and hence signed it). The "punk" way is to
> check the
> > so-called fingerprint - a cryptographic hash calculated on the
> certificate's
> > data - to match whatever stored at the authenticating side.
> >
> > Add to the picture that the server usually wants to have a way to prevent
> > certain clients - which would otherwise be properly auth

[go-nuts] ListenAndServeTLS() (pem and key files for private network)

2022-06-27 Thread Hugh Myrie
I wish to create a secure private network using a self-signed certificate 
with a Go web server: See the following code block:

// Code 
err := http.ListenAndServeTLS(":"+port, "auto.org.pem", 
"auto.org-key.pem", handler)
if err != nil {

logError((err.Error()))
log.Fatal("ListenAndServe: ", err)
}
// End of Code

Could I auto  generate (and register) the .pem and .key files using GO?  I 
wish to create a trust certificate if there files do not exist.

I came across the following website:

"https://gist.github.com/shaneutt/5e1995295cff6721c89a71d13a71c251";

I am not sure how to implement this. Your help is appreciated.

-- 
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/6ce2a407-600d-44b7-97d1-53e90e91e7c8n%40googlegroups.com.


Re: [go-nuts] Re: Upgrade to Go1.16 from Go1.14 broke my query

2021-06-28 Thread Hugh Myrie
I opened an issue there. Thanks for your help.

On Mon, Jun 28, 2021 at 11:09 AM Brian Candler  wrote:

> I suggest the issue tracker for the firebirdsql library is the right place.
>
> On Monday, 28 June 2021 at 16:17:22 UTC+1 hugh@gmail.com wrote:
>
>> Stripped down file is attached.
>>
>> Go version 1.14.15
>> DB was created in Firebird 3.0.
>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/BHxTxzCpUB4/unsubscribe.
> To unsubscribe from this group and all its topics, 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/5dbecbbf-fe1f-4020-9a53-6b6fc8a0f977n%40googlegroups.com
> 
> .
>


-- 
http://www.jaxtr.com/blessed_hope

-- 
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/CAN-X3%3DbmhHUtmeEOiGAXj%3D6pf1GjzixVCTpUiSHPg3_9Y5x39A%40mail.gmail.com.


Re: [go-nuts] Re: Upgrade to Go1.16 from Go1.14 broke my query

2021-06-28 Thread Hugh Myrie
Stripped down file is attached. 

Go version 1.14.15
DB was created in Firebird 3.0.

-- 
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/ee328f6d-39a1-4f17-bd22-4cc3a7b396can%40googlegroups.com.
<>


Re: [go-nuts] Re: Upgrade to Go1.16 from Go1.14 broke my query

2021-06-28 Thread Hugh Myrie
Let me do that.

On Mon, Jun 28, 2021 at 8:57 AM Brian Candler  wrote:

> Can you make that into a standalone program, which doesn't use a HTTP
> exchange but just does the query and exits?  If the problem is still there,
> then you have a very nice test case to submit upstream (along with details
> of exactly what version of firebird you're using, what platform you're
> running on etc)
>
> If the problem goes away, but comes back when it's run as a HTTP server,
> then make a standalone program that contains a HTTP server and also
> demonstrates the problem.  What you've shown so far is just a snippet which
> isn't runnable as-is.
>
> On Monday, 28 June 2021 at 12:48:23 UTC+1 hugh@gmail.com wrote:
>
>> Update:
>>
>> I created a* new* database with only one table with two fields. Added
>> three records. I have also created a stripped down version of the Go
>> program with a function that query the table. The problem persist.
>>
>>
>> *Table:*
>>  CREATE TABLE TESTR
>> (
>>   CODE Varchar(5) NOT NULL,
>>   DESCRIPTION Varchar(30) NOT NULL
>> );
>>
>> *The Data.*
>>
>> insert into testr (code, description) values ('123', 'Data 1');
>> insert into testr (code, description) values ('163', 'Data 5');
>> insert into testr (code, description) values ('653', 'Data 2');
>>
>> *The Go function:*
>>
>> func getTest(w http.ResponseWriter, r *http.Request) {
>>
>> type test struct {
>> Code  string  `json:"code"`
>> Description   string  `json:"description"`
>> }
>> tests := []test{}
>>
>>
>> conn, _ := sql.Open("firebirdsql", datapath)
>> defer conn.Close()
>> rows, err := conn.Query("select code, description from testr")
>> if err != nil {
>> respondWithError(w, http.StatusBadRequest, err.Error())
>> logError(err.Error())
>> return
>> }
>>
>> defer rows.Close()
>> for rows.Next() {
>> var t test
>> err := rows.Scan(&t.Code, &t.Description)
>> if err != nil {
>> respondWithError(w, http.StatusBadRequest, err.Error())
>> logError(err.Error())
>> return
>> }
>> tests = append(tests, t)
>> }
>> err = rows.Err()
>> if err != nil {
>> respondWithError(w, http.StatusBadRequest, err.Error())
>> logError(err.Error())
>> return
>> }
>> respondWithJSON(w, http.StatusOK, tests)
>>
>> }
>>
>> *The call (from the browser):*
>>
>> 192.168.0.13:8080/test
>>
>> *The Error*:
>>
>> {"error":"Dynamic SQL Error\nSQL error code = -303\narithmetic exception,
>> numeric overflow, or string truncation\nstring right truncation\nexpected
>> length 1, actual 5\n"}
>>
>>
>> On Monday, June 28, 2021 at 2:08:55 AM UTC-5 Brian Candler wrote:
>>
>>> Then it sounds to me like the problem is with your application, and/or
>>> with the data in your database, and that the problem has always been there.
>>>
>>> The error talks about "string right truncation". My suggestion would be
>>> to take your SQL query and start removing some fields from it, starting
>>> with the "message" and "binary4" fields.  In particular, is it possible
>>> that some value in your "mesg" column has more than 400 characters?
>>>
>>> sql2 := "select tax1, fees1, fees2, minus_stk, discount1, discount2,
>>> discount3, discount4, elderly, cast(mesg as varchar(400)), binary4 from
>>> system"
>>> ...
>>> err := rows.Scan(&p.Tax1, &p.Fees1, &p.Fees2, &p.Minus_stk,
>>> &p.Discount1, &p.Discount2, &p.Discount3, &p.Discount4, &p.Elderly,
>>> &p.Message, &p.Binary4)
>>>
>>> -->
>>>
>>> sql2 := "select tax1, fees1, fees2, minus_stk, discount1, discount2,
>>> discount3, discount4, elderly from system"
>>> ...
>>> err := rows.Scan(&p.Tax1, &p.Fees1, &p.Fees2, &p.Minus_stk,
>>> &p.Discount1, &p.Discount2, &p.Discount3, &p.Discount4, &p.Elderly)
>>>
>>> (Aside: those values have type "NullString" but your code snippet didn't
>>> show how that type was defined)
>>>
>>> If that doesn't make a difference, start chopping out the other fields.
>>>
>>> On Monday, 28 June 2021 at 01:12:51 UTC+1 hugh@gmail.com wrote:
>>>
>

Re: [go-nuts] Re: Upgrade to Go1.16 from Go1.14 broke my query

2021-06-28 Thread Hugh Myrie
Update: 

I created a* new* database with only one table with two fields. Added three 
records. I have also created a stripped down version of the Go program with 
a function that query the table. The problem persist.


*Table:*
 CREATE TABLE TESTR
(
  CODE Varchar(5) NOT NULL,
  DESCRIPTION Varchar(30) NOT NULL
);

*The Data.*

insert into testr (code, description) values ('123', 'Data 1');
insert into testr (code, description) values ('163', 'Data 5');
insert into testr (code, description) values ('653', 'Data 2');

*The Go function:*

func getTest(w http.ResponseWriter, r *http.Request) {

type test struct {
Code  string  `json:"code"`
Description   string  `json:"description"`
}
tests := []test{}


conn, _ := sql.Open("firebirdsql", datapath)
defer conn.Close()
rows, err := conn.Query("select code, description from testr")
if err != nil {
respondWithError(w, http.StatusBadRequest, err.Error())
logError(err.Error())
return
}

defer rows.Close()
for rows.Next() {
var t test
err := rows.Scan(&t.Code, &t.Description)
if err != nil {
respondWithError(w, http.StatusBadRequest, err.Error())
logError(err.Error())
return
}
tests = append(tests, t)
}
err = rows.Err()
if err != nil {
respondWithError(w, http.StatusBadRequest, err.Error())
logError(err.Error())
return
}
respondWithJSON(w, http.StatusOK, tests)

}

*The call (from the browser):*

192.168.0.13:8080/test

*The Error*:

{"error":"Dynamic SQL Error\nSQL error code = -303\narithmetic exception, 
numeric overflow, or string truncation\nstring right truncation\nexpected 
length 1, actual 5\n"}


On Monday, June 28, 2021 at 2:08:55 AM UTC-5 Brian Candler wrote:

> Then it sounds to me like the problem is with your application, and/or 
> with the data in your database, and that the problem has always been there.
>
> The error talks about "string right truncation". My suggestion would be to 
> take your SQL query and start removing some fields from it, starting with 
> the "message" and "binary4" fields.  In particular, is it possible that 
> some value in your "mesg" column has more than 400 characters?
>
> sql2 := "select tax1, fees1, fees2, minus_stk, discount1, discount2, 
> discount3, discount4, elderly, cast(mesg as varchar(400)), binary4 from 
> system"
> ...
> err := rows.Scan(&p.Tax1, &p.Fees1, &p.Fees2, &p.Minus_stk, &p.Discount1, 
> &p.Discount2, &p.Discount3, &p.Discount4, &p.Elderly, &p.Message, 
> &p.Binary4)
>
> -->
>
> sql2 := "select tax1, fees1, fees2, minus_stk, discount1, discount2, 
> discount3, discount4, elderly from system"
> ...
> err := rows.Scan(&p.Tax1, &p.Fees1, &p.Fees2, &p.Minus_stk, &p.Discount1, 
> &p.Discount2, &p.Discount3, &p.Discount4, &p.Elderly)
>
> (Aside: those values have type "NullString" but your code snippet didn't 
> show how that type was defined)
>
> If that doesn't make a difference, start chopping out the other fields.
>
> On Monday, 28 June 2021 at 01:12:51 UTC+1 hugh@gmail.com wrote:
>
>> Update: 
>>
>> I did a re-installation of Go1.14.15. Reinstalled the FirebirdSQL driver, 
>> yet the problem persist. 
>>
>> On Sunday, June 27, 2021 at 1:43:23 PM UTC-5 Hugh Myrie wrote:
>>
>>> The version I saw in the go.mod file was v0.9.1. However, looking at the 
>>> modified date of the files in the library folder was last year. So I 
>>> deleted the library and reinstalled it . I suppose doing a "go get" without 
>>> specifying a version would retrieve the latest version. Correct me if I'm 
>>> wrong here.
>>>
>>> I'm trying to get back to go1.14 to conduct further tests before making 
>>> a standalone test.
>>>
>>> On Sun, Jun 27, 2021 at 4:03 AM Brian Candler  wrote:
>>>
>>>> On Sunday, 27 June 2021 at 03:27:28 UTC+1 hugh@gmail.com wrote:
>>>>
>>>>> I agree. So far, I've Installed Go1.15, reinstalled the Firebird 
>>>>> library. 
>>>>
>>>>
>>>> Which version?  The latest tagged version (v0.9.1) or the tip of the 
>>>> master branch?
>>>>
>>>> Having said that: the commit 
>>>> <https://github.com/nakagami/firebirdsql/commit/ab7f07a652d65ac925b17003dcac22e377d810a8>
>>>>  
>>>> which changes the current supported version to 1.15, does nothing except 
>>>> change the version number in go.mod; and it was applied immediately after 
>>>> the v0.9.1 tag. 
>>>>  
>&

Re: [go-nuts] Re: Upgrade to Go1.16 from Go1.14 broke my query

2021-06-27 Thread Hugh Myrie
Update: 

I did a re-installation of Go1.14.15. Reinstalled the FirebirdSQL driver, 
yet the problem persist. 

On Sunday, June 27, 2021 at 1:43:23 PM UTC-5 Hugh Myrie wrote:

> The version I saw in the go.mod file was v0.9.1. However, looking at the 
> modified date of the files in the library folder was last year. So I 
> deleted the library and reinstalled it . I suppose doing a "go get" without 
> specifying a version would retrieve the latest version. Correct me if I'm 
> wrong here.
>
> I'm trying to get back to go1.14 to conduct further tests before making a 
> standalone test.
>
> On Sun, Jun 27, 2021 at 4:03 AM Brian Candler  wrote:
>
>> On Sunday, 27 June 2021 at 03:27:28 UTC+1 hugh@gmail.com wrote:
>>
>>> I agree. So far, I've Installed Go1.15, reinstalled the Firebird 
>>> library. 
>>
>>
>> Which version?  The latest tagged version (v0.9.1) or the tip of the 
>> master branch?
>>
>> Having said that: the commit 
>> <https://github.com/nakagami/firebirdsql/commit/ab7f07a652d65ac925b17003dcac22e377d810a8>
>>  
>> which changes the current supported version to 1.15, does nothing except 
>> change the version number in go.mod; and it was applied immediately after 
>> the v0.9.1 tag. 
>>  
>>
>>> Compiled using Go1.15 and the problem persist.
>>
>>
>> If you can make a standalone test program which replicates the problem, 
>> then I suggest you open an issue on the firebirdsql repo.  All developers 
>> love good reproducible bug reports with code that reproduces the bug :-)
>>
>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "golang-nuts" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/golang-nuts/BHxTxzCpUB4/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> golang-nuts...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/6bb8c44e-e564-4685-aecf-7c8bffb3269cn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/6bb8c44e-e564-4685-aecf-7c8bffb3269cn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> http://www.jaxtr.com/blessed_hope
>

-- 
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/9831eb07-b3e5-4274-abce-6609a4a8d357n%40googlegroups.com.


Re: [go-nuts] Re: Upgrade to Go1.16 from Go1.14 broke my query

2021-06-27 Thread Hugh Myrie
The version I saw in the go.mod file was v0.9.1. However, looking at the
modified date of the files in the library folder was last year. So I
deleted the library and reinstalled it . I suppose doing a "go get" without
specifying a version would retrieve the latest version. Correct me if I'm
wrong here.

I'm trying to get back to go1.14 to conduct further tests before making a
standalone test.

On Sun, Jun 27, 2021 at 4:03 AM Brian Candler  wrote:

> On Sunday, 27 June 2021 at 03:27:28 UTC+1 hugh@gmail.com wrote:
>
>> I agree. So far, I've Installed Go1.15, reinstalled the Firebird library.
>
>
> Which version?  The latest tagged version (v0.9.1) or the tip of the
> master branch?
>
> Having said that: the commit
> 
> which changes the current supported version to 1.15, does nothing except
> change the version number in go.mod; and it was applied immediately after
> the v0.9.1 tag.
>
>
>> Compiled using Go1.15 and the problem persist.
>
>
> If you can make a standalone test program which replicates the problem,
> then I suggest you open an issue on the firebirdsql repo.  All developers
> love good reproducible bug reports with code that reproduces the bug :-)
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/BHxTxzCpUB4/unsubscribe.
> To unsubscribe from this group and all its topics, 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/6bb8c44e-e564-4685-aecf-7c8bffb3269cn%40googlegroups.com
> 
> .
>


-- 
http://www.jaxtr.com/blessed_hope

-- 
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/CAN-X3%3DbfcfSociGwauvCf_nDfU42o8yLUUvTxLRzTqGRhEwzMA%40mail.gmail.com.


Re: [go-nuts] Re: Upgrade to Go1.16 from Go1.14 broke my query

2021-06-26 Thread Hugh Myrie
I agree. So far, I've Installed Go1.15, reinstalled the Firebird library. 
Compiled using Go1.15 and the problem persist. Trying to install Go1.14.9 
but I'm not yet successful. I suppose Go1.14 is now deprecated so the 
normal procedure to have it coexist with the later versions doesn't work.

On Saturday, June 26, 2021 at 1:51:38 PM UTC-5 rol...@gmail.com wrote:

> When the query works with other DBs & their Go  drivers this strongly 
> suggest that there is some incompatibility of the Firebird vs. Go 16.x.
>
> Thus you should check the suggestion from Jake to update the Firebird 
> driver for Go.
>
> In the Github project 
> https://github.com/nakagami/firebirdsql/commits/master  
> <https://github.com/nakagami/firebirdsql/commits/master>
>
> In Commits on Jun 21, 2021 used go version in go.mod was change to 1.15 
> and the readme file now startes that go 1.15 or newer is supported. May be 
> this helps.
>
> BR,
> Roland
>
> Am Sa., 26. Juni 2021 um 19:03 Uhr schrieb Hugh Myrie  >:
>
>> That is a possibility. I didn't try to rebuild under Go1.14., but I will 
>> give that a try.  Interestingly, one "select query" worked but the others 
>> failed with similar error messages. After upgrading to G1.16 I ran "go 
>> tidy" which downloaded the libraries and create a "mod" file in the working 
>> folder, so I take it that the libraries are correct. I'll try your 
>> suggestion and let you know.
>>
>>   I am able to access and read MySQL and MariaDB tables with the updated 
>> Go version. 
>>
>> On Saturday, June 26, 2021 at 10:43:15 AM UTC-5 jake...@gmail.com wrote:
>>
>>> Is it possible that the version of the library you are using also 
>>> changed when you changed versions of Go?
>>> Have you tried building again, on the same machine, using Go 1.14 to 
>>> make sure that the only difference is the Go language version?
>>>
>>> On Thursday, June 24, 2021 at 11:14:30 AM UTC-4 hugh@gmail.com 
>>> wrote:
>>>
>>>> I recently updated my Go version to 1.16 and for all my queries I now 
>>>> get an error:
>>>>
>>>> {"error":"Dynamic SQL Error\nSQL error code = -303\narithmetic 
>>>> exception, numeric overflow, or string truncation\nstring right 
>>>> truncation\n"}
>>>>
>>>> I'm using  the package:   _ "github.com/nakagami/firebirdsql"
>>>>
>>>> The following is a simple function:
>>>>
>>>> func getSystem(w http.ResponseWriter, r *http.Request) {
>>>> type system struct {
>>>> Tax1float64  `json:"tax1"`
>>>> Fees1  float64  `json:"fees1"`
>>>> Fees2   float64  `json:"fees2"`
>>>> Minus_stk string `json:"minus_stk"`
>>>> Discount1 float64 `json:"discount1"`
>>>> Discount2 float64 `json:"discount2"`
>>>> Discount3 float64 `json:"discount3"`
>>>> Discount4 float64 `json:"discount4"`
>>>> Elderly float64 `json:"elderly"`
>>>> Message NullString `json:"message"`
>>>> Binary4 NullString `json:"binary4"`
>>>> }
>>>> sysdata := []system{}
>>>> sql2 := "select tax1, fees1, fees2, minus_stk, discount1, discount2, 
>>>> discount3, discount4, elderly, cast(mesg as varchar(400)), binary4 from 
>>>> system"
>>>> conn, _ := sql.Open("firebirdsql",  datapath)
>>>> defer conn.Close()
>>>> rows, err := conn.Query(sql2)
>>>> if err != nil {
>>>> respondWithError(w, http.StatusBadRequest, err.Error())
>>>> return
>>>> }
>>>> defer rows.Close()
>>>> for rows.Next() {
>>>> var p system
>>>> err := rows.Scan(&p.Tax1, &p.Fees1, &p.Fees2, &p.Minus_stk, 
>>>> &p.Discount1, &p.Discount2, &p.Discount3, &p.Discount4, &p.Elderly, 
>>>> &p.Message, &p.Binary4)
>>>> if err != nil {
>>>> respondWithError(w, http.StatusBadRequest, err.Error())
>>>> return
>>>> }
>>>> sysdata = append(sysdata, p)
>>>> }
>>>> err = rows.Err()  //  <--- errors seem to thrown here.
>>>> if err != nil {
>>>> respondWithError(w, http.StatusBadRequest, err.Error())
>>>> return
>>>> }
>>>> respondWithJSON(w, http.StatusOK, sysdata)
>>>> }
>>>>
>>>> Your help would be appreciated.
>>>>
>>>> I'm using Firebird 2.5. Everything worked under the previous version of 
>>>> Go. I am scanning for null values so I don't believe that is the issue.
>>>>
>>> -- 
>> 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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/90a32eff-32c0-4d6d-a822-e843bbc5b31an%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/90a32eff-32c0-4d6d-a822-e843bbc5b31an%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/657cdad5-5d76-4dbd-b83f-8a4885c73739n%40googlegroups.com.


[go-nuts] Re: Upgrade to Go1.16 from Go1.14 broke my query

2021-06-26 Thread Hugh Myrie
That is a possibility. I didn't try to rebuild under Go1.14., but I will 
give that a try.  Interestingly, one "select query" worked but the others 
failed with similar error messages. After upgrading to G1.16 I ran "go 
tidy" which downloaded the libraries and create a "mod" file in the working 
folder, so I take it that the libraries are correct. I'll try your 
suggestion and let you know.

  I am able to access and read MySQL and MariaDB tables with the updated Go 
version. 

On Saturday, June 26, 2021 at 10:43:15 AM UTC-5 jake...@gmail.com wrote:

> Is it possible that the version of the library you are using also changed 
> when you changed versions of Go?
> Have you tried building again, on the same machine, using Go 1.14 to make 
> sure that the only difference is the Go language version?
>
> On Thursday, June 24, 2021 at 11:14:30 AM UTC-4 hugh@gmail.com wrote:
>
>> I recently updated my Go version to 1.16 and for all my queries I now get 
>> an error:
>>
>> {"error":"Dynamic SQL Error\nSQL error code = -303\narithmetic exception, 
>> numeric overflow, or string truncation\nstring right truncation\n"}
>>
>> I'm using  the package:   _ "github.com/nakagami/firebirdsql"
>>
>> The following is a simple function:
>>
>> func getSystem(w http.ResponseWriter, r *http.Request) {
>> type system struct {
>> Tax1float64  `json:"tax1"`
>> Fees1  float64  `json:"fees1"`
>> Fees2   float64  `json:"fees2"`
>> Minus_stk string `json:"minus_stk"`
>> Discount1 float64 `json:"discount1"`
>> Discount2 float64 `json:"discount2"`
>> Discount3 float64 `json:"discount3"`
>> Discount4 float64 `json:"discount4"`
>> Elderly float64 `json:"elderly"`
>> Message NullString `json:"message"`
>> Binary4 NullString `json:"binary4"`
>> }
>> sysdata := []system{}
>> sql2 := "select tax1, fees1, fees2, minus_stk, discount1, discount2, 
>> discount3, discount4, elderly, cast(mesg as varchar(400)), binary4 from 
>> system"
>> conn, _ := sql.Open("firebirdsql",  datapath)
>> defer conn.Close()
>> rows, err := conn.Query(sql2)
>> if err != nil {
>> respondWithError(w, http.StatusBadRequest, err.Error())
>> return
>> }
>> defer rows.Close()
>> for rows.Next() {
>> var p system
>> err := rows.Scan(&p.Tax1, &p.Fees1, &p.Fees2, &p.Minus_stk, &p.Discount1, 
>> &p.Discount2, &p.Discount3, &p.Discount4, &p.Elderly, &p.Message, 
>> &p.Binary4)
>> if err != nil {
>> respondWithError(w, http.StatusBadRequest, err.Error())
>> return
>> }
>> sysdata = append(sysdata, p)
>> }
>> err = rows.Err()  //  <--- errors seem to thrown here.
>> if err != nil {
>> respondWithError(w, http.StatusBadRequest, err.Error())
>> return
>> }
>> respondWithJSON(w, http.StatusOK, sysdata)
>> }
>>
>> Your help would be appreciated.
>>
>> I'm using Firebird 2.5. Everything worked under the previous version of 
>> Go. I am scanning for null values so I don't believe that is the issue.
>>
>

-- 
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/90a32eff-32c0-4d6d-a822-e843bbc5b31an%40googlegroups.com.


Re: [go-nuts] Upgrade to Go1.16 from Go1.14 broke my query

2021-06-25 Thread Hugh Myrie
Yes. It seems that's the case. I'm floored.

On Fri, Jun 25, 2021 at 7:17 PM Hugh Myrie  wrote:

> Bypassing the error returns an empty result set.
>
>  Additional information: "string right truncation /expected length 0,
> actual 3". In the DB the Code field is varchar(3) and Description is
> Varchar(30).
>
> It seems to have something to do with the return field size and the size
> expected in Golang.
> On Friday, June 25, 2021 at 3:24:25 AM UTC-5 rol...@gmail.com wrote:
>
>> Hello,
>>
>> Am Do., 24. Juni 2021 um 18:14 Uhr schrieb Hugh Myrie > >:
>>
>>> I recently updated my Go version to 1.16 and for all my queries I now
>>> get an error:
>>>
>>> {"error":"Dynamic SQL Error\nSQL error code = -303\narithmetic
>>> exception, numeric overflow, or string truncation\nstring right
>>> truncation\n"}
>>>
>>> I'm using  the package:   _ "github.com/nakagami/firebirdsql"
>>>
>>> The following is a simple function:
>>>
>>> func getSystem(w http.ResponseWriter, r *http.Request) {
>>> type system struct {
>>> Tax1float64  `json:"tax1"`
>>> Fees1  float64  `json:"fees1"`
>>> Fees2   float64  `json:"fees2"`
>>> Minus_stk string `json:"minus_stk"`
>>> Discount1 float64 `json:"discount1"`
>>> Discount2 float64 `json:"discount2"`
>>> Discount3 float64 `json:"discount3"`
>>> Discount4 float64 `json:"discount4"`
>>> Elderly float64 `json:"elderly"`
>>> Message NullString `json:"message"`
>>> Binary4 NullString `json:"binary4"`
>>> }
>>> sysdata := []system{}
>>> sql2 := "select tax1, fees1, fees2, minus_stk, discount1, discount2,
>>> discount3, discount4, elderly, cast(mesg as varchar(400)), binary4 from
>>> system"
>>> conn, _ := sql.Open("firebirdsql",  datapath)
>>> defer conn.Close()
>>> rows, err := conn.Query(sql2)
>>> if err != nil {
>>> respondWithError(w, http.StatusBadRequest, err.Error())
>>> return
>>> }
>>> defer rows.Close()
>>> for rows.Next() {
>>> var p system
>>> err := rows.Scan(&p.Tax1, &p.Fees1, &p.Fees2, &p.Minus_stk,
>>> &p.Discount1, &p.Discount2, &p.Discount3, &p.Discount4, &p.Elderly,
>>> &p.Message, &p.Binary4)
>>> if err != nil {
>>> respondWithError(w, http.StatusBadRequest, err.Error())
>>> return
>>> }
>>> sysdata = append(sysdata, p)
>>> }
>>> err = rows.Err()  //  <--- errors seem to thrown here.
>>> if err != nil {
>>> respondWithError(w, http.StatusBadRequest, err.Error())
>>> return
>>> }
>>> respondWithJSON(w, http.StatusOK, sysdata)
>>> }
>>>
>>> Your help would be appreciated.
>>>
>>> I'm using Firebird 2.5. Everything worked under the previous version of
>>> Go. I am scanning for null values so I don't believe that is the issue.
>>>
>>> ust a wild guess not "biased" by any close knowledge of Firebird DB or
>> the above mentioned Go module: there has something changed with handling of
>> rows.Next() when the last row of data has been passed. This guess is based
>> on the fact that your mark the error only occurs after reading all data
>> rows.
>>
>> I would try to log a warning to server log and try to return the JSON
>> data instead of returning http.StatusBadRequest. It may be that the data is
>> valid.
>>
>> BR,
>> Roland
>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/BHxTxzCpUB4/unsubscribe.
> To unsubscribe from this group and all its topics, 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/9f77d3d8-a666-48f1-8da8-43b0a076a132n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/9f77d3d8-a666-48f1-8da8-43b0a076a132n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
http://www.jaxtr.com/blessed_hope

-- 
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/CAN-X3%3DYvTqF_zAXnjRuX5pPe2uLd3ZkS7szhUP01C4S5S%2BOEcQ%40mail.gmail.com.


Re: [go-nuts] Upgrade to Go1.16 from Go1.14 broke my query

2021-06-25 Thread Hugh Myrie
Bypassing the error returns an empty result set. 

 Additional information: "string right truncation /expected length 0, 
actual 3". In the DB the Code field is varchar(3) and Description is 
Varchar(30).

It seems to have something to do with the return field size and the size 
expected in Golang.
On Friday, June 25, 2021 at 3:24:25 AM UTC-5 rol...@gmail.com wrote:

> Hello,
>
> Am Do., 24. Juni 2021 um 18:14 Uhr schrieb Hugh Myrie  >:
>
>> I recently updated my Go version to 1.16 and for all my queries I now get 
>> an error:
>>
>> {"error":"Dynamic SQL Error\nSQL error code = -303\narithmetic exception, 
>> numeric overflow, or string truncation\nstring right truncation\n"}
>>
>> I'm using  the package:   _ "github.com/nakagami/firebirdsql"
>>
>> The following is a simple function:
>>
>> func getSystem(w http.ResponseWriter, r *http.Request) {
>> type system struct {
>> Tax1float64  `json:"tax1"`
>> Fees1  float64  `json:"fees1"`
>> Fees2   float64  `json:"fees2"`
>> Minus_stk string `json:"minus_stk"`
>> Discount1 float64 `json:"discount1"`
>> Discount2 float64 `json:"discount2"`
>> Discount3 float64 `json:"discount3"`
>> Discount4 float64 `json:"discount4"`
>> Elderly float64 `json:"elderly"`
>> Message NullString `json:"message"`
>> Binary4 NullString `json:"binary4"`
>> }
>> sysdata := []system{}
>> sql2 := "select tax1, fees1, fees2, minus_stk, discount1, discount2, 
>> discount3, discount4, elderly, cast(mesg as varchar(400)), binary4 from 
>> system"
>> conn, _ := sql.Open("firebirdsql",  datapath)
>> defer conn.Close()
>> rows, err := conn.Query(sql2)
>> if err != nil {
>> respondWithError(w, http.StatusBadRequest, err.Error())
>> return
>> }
>> defer rows.Close()
>> for rows.Next() {
>> var p system
>> err := rows.Scan(&p.Tax1, &p.Fees1, &p.Fees2, &p.Minus_stk, &p.Discount1, 
>> &p.Discount2, &p.Discount3, &p.Discount4, &p.Elderly, &p.Message, 
>> &p.Binary4)
>> if err != nil {
>> respondWithError(w, http.StatusBadRequest, err.Error())
>> return
>> }
>> sysdata = append(sysdata, p)
>> }
>> err = rows.Err()  //  <--- errors seem to thrown here.
>> if err != nil {
>> respondWithError(w, http.StatusBadRequest, err.Error())
>> return
>> }
>> respondWithJSON(w, http.StatusOK, sysdata)
>> }
>>
>> Your help would be appreciated.
>>
>> I'm using Firebird 2.5. Everything worked under the previous version of 
>> Go. I am scanning for null values so I don't believe that is the issue.
>>
>> ust a wild guess not "biased" by any close knowledge of Firebird DB or 
> the above mentioned Go module: there has something changed with handling of 
> rows.Next() when the last row of data has been passed. This guess is based 
> on the fact that your mark the error only occurs after reading all data 
> rows.
>
> I would try to log a warning to server log and try to return the JSON data 
> instead of returning http.StatusBadRequest. It may be that the data is 
> valid.
>  
> BR,
> Roland
>
>

-- 
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/9f77d3d8-a666-48f1-8da8-43b0a076a132n%40googlegroups.com.


[go-nuts] Upgrade to Go1.16 from Go1.14 broke my query

2021-06-24 Thread Hugh Myrie
I recently updated my Go version to 1.16 and for all my queries I now get 
an error:

{"error":"Dynamic SQL Error\nSQL error code = -303\narithmetic exception, 
numeric overflow, or string truncation\nstring right truncation\n"}

I'm using  the package:   _ "github.com/nakagami/firebirdsql"

The following is a simple function:

func getSystem(w http.ResponseWriter, r *http.Request) {
type system struct {
Tax1float64  `json:"tax1"`
Fees1  float64  `json:"fees1"`
Fees2   float64  `json:"fees2"`
Minus_stk string `json:"minus_stk"`
Discount1 float64 `json:"discount1"`
Discount2 float64 `json:"discount2"`
Discount3 float64 `json:"discount3"`
Discount4 float64 `json:"discount4"`
Elderly float64 `json:"elderly"`
Message NullString `json:"message"`
Binary4 NullString `json:"binary4"`
}
sysdata := []system{}
sql2 := "select tax1, fees1, fees2, minus_stk, discount1, discount2, 
discount3, discount4, elderly, cast(mesg as varchar(400)), binary4 from 
system"
conn, _ := sql.Open("firebirdsql",  datapath)
defer conn.Close()
rows, err := conn.Query(sql2)
if err != nil {
respondWithError(w, http.StatusBadRequest, err.Error())
return
}
defer rows.Close()
for rows.Next() {
var p system
err := rows.Scan(&p.Tax1, &p.Fees1, &p.Fees2, &p.Minus_stk, &p.Discount1, 
&p.Discount2, &p.Discount3, &p.Discount4, &p.Elderly, &p.Message, 
&p.Binary4)
if err != nil {
respondWithError(w, http.StatusBadRequest, err.Error())
return
}
sysdata = append(sysdata, p)
}
err = rows.Err()  //  <--- errors seem to thrown here.
if err != nil {
respondWithError(w, http.StatusBadRequest, err.Error())
return
}
respondWithJSON(w, http.StatusOK, sysdata)
}

Your help would be appreciated.

I'm using Firebird 2.5. Everything worked under the previous version of Go. 
I am scanning for null values so I don't believe that is the issue.

-- 
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/3594e3a5-b6e7-431c-8719-5f5dbdf9b933n%40googlegroups.com.


Re: [go-nuts] Sending Escape codes to printer

2021-04-03 Thread Hugh Myrie
Awesome, thanks!

On Sat, Apr 3, 2021 at 5:15 PM Kurtis Rader  wrote:

> Start here: https://golang.org/ref/spec#Rune_literals. Then read the next
> section about string literals and note that rune escape sequences are
> recognized inside double-quoted strings. For example, your feed paper
> command could be written "\033J\004" or "\x1bJ\x04". There are other ways,
> of course, to construct such strings that may be more readable by using
> constant declarations such as `const Esc '\x1b'`.
>
> On Sat, Apr 3, 2021 at 2:55 PM Hugh Myrie  wrote:
>
>> Given the following, how do I send escape codes to print?
>>
>> for _, line := range lines {
>> fmt.Fprintf(p, "%s\r\n", line)
>> }
>>
>> How do I send escape sequences using the above print command?
>>
>> Below is a C# example:
>>
>> output = Chr(&H1D) & "V" & Chr(66) & Chr(0);
>>
>> I want to send the escape codes to a receipt printer to control the
>> perform cetrain functions.
>>
>> Some commands include:
>> ESC "J" 4  <--Feed paper
>>
>>  GS "!" 0x11  <-- change character size
>>
>> --
>> 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/b420e7fc-55c4-452c-822e-e84a3b96da85n%40googlegroups.com
>> <https://groups.google.com/d/msgid/golang-nuts/b420e7fc-55c4-452c-822e-e84a3b96da85n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>


-- 
http://www.jaxtr.com/blessed_hope

-- 
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/CAN-X3%3DZkwmbhhKiS6CVCmuAGzbzvGOLgqJT5%2BwFCjn8zLwv7Rw%40mail.gmail.com.


[go-nuts] Sending Escape codes to printer

2021-04-03 Thread Hugh Myrie
Given the following, how do I send escape codes to print?

for _, line := range lines {
fmt.Fprintf(p, "%s\r\n", line)
}

How do I send escape sequences using the above print command?

Below is a C# example:

output = Chr(&H1D) & "V" & Chr(66) & Chr(0);

I want to send the escape codes to a receipt printer to control the perform 
cetrain functions.

Some commands include:
ESC "J" 4  <--Feed paper 

 GS "!" 0x11  <-- change character size

-- 
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/b420e7fc-55c4-452c-822e-e84a3b96da85n%40googlegroups.com.


[go-nuts] Using nested struct to save master-detail POST request

2021-03-21 Thread Hugh Myrie
I am able to decode the body of a POST request 
using json.NewDecoder(r.Body)., then save the result to a database. 

Example:

type Product struct {
IDint  `json:"id"`   
Description  string  `json:"description"`
Price   float64 `json:"price"`
Packsize int `json:"packsize"`
Count1 int `json:"count1"`
Bin string `json:"bin"`
Qoh int `json:"qoh"`
}

items := []Product{}

err := json.NewDecoder(r.Body).Decode(&items)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
fmt.Println("Error occurs here")
log.Printf(err.Error())
return
}

How can I use a nested struct to produce two slices from an incoming 
(master-detail) POST request, in the form:

[{receipt: 1, date: '01/01/2021', customer: 'Cash' , subtotal: 10.70,
 detail: [{receipt: 1, description: 'item1', price: 2.00, qty: 2},
  {receipt: 1, description: 'item2', price: 2.50, qty: 1},
  {receipt: 1, description: 'item3', price: 4.20, qty: 1}]
]

I am trying to avoid sending two POST requests, master followed by detail.

-- 
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/1b5febdd-f4f0-4e56-86e9-a1fe0721d7ffn%40googlegroups.com.


[go-nuts] Serving SPA and routing for endpoints

2021-03-10 Thread Hugh Myrie
I am trying to follow the example as described in the 
link: https://github.com/gorilla/mux, to serve a single page application 
(Angular) from Go and also to route my endpoints.

My endpoints are not being routed although the index.html is served. My 
main function has the following format:

//===
func main() {
getParams()
r := mux.NewRouter()
// Routes consist of a path and a handler function.

//---
usersR := r.PathPrefix("/users").Subrouter()
usersR.Path("").Methods(http.MethodPost).HandlerFunc(createUser)
usersR.Path("/{id}").Methods(http.MethodGet).HandlerFunc(getUserByID)
usersR.Path("/`{id}").Methods(http.MethodPut).HandlerFunc(updateUser)
usersR.Path("/{id}").Methods(http.MethodDelete).HandlerFunc(deleteUser)

productR := r.PathPrefix("/product").Subrouter()
productR.Path("").Methods(http.MethodGet).HandlerFunc(getProductInfo)
productR.Path("/{id}").Methods(http.MethodGet).HandlerFunc(getProductID)

   
c := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowCredentials: true,
})
handler := c.Handler(r)
r.HandleFunc("/stockcount", getStock)
spa := spaHandler{staticPath: "public", indexPath: "index.html"}
r.PathPrefix("/{_:.*}").Handler(spa)   

ip := GetOutboundIP()
portAvailable(port)
fmt.Printf("Start listening on %s // %s \n", ip, port)
http.ListenAndServe(":"+port, handler)
}

//===

All request seems to be handled by the spaHandler so I received a bad 
request when trying to reach an endpoint.

500 (Internal Server Error)

Also how do I re-route for path "/home" to the index.html?

-- 
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/ce3d1ddc-2c70-48c7-bdc8-1ea0361cc918n%40googlegroups.com.


[go-nuts] Re: I want to save a file from an incoming POST request and upon request return the file in a GET request as JSON data.

2021-03-02 Thread Hugh Myrie
Brilliant!! Thanks Tamas, that worked perfectly.

On Tuesday, March 2, 2021 at 4:14:10 PM UTC-5 Tamás Gulácsi wrote:

> If I understand correctly, you receive "bodyBytes", store it in a file, 
> and later want to serve it.
> Then a `w.Write(b)` would suffice.
> Or without reading the whole file into memory: `io.Copy(w, file)`.
>
> hugh@gmail.com a következőt írta (2021. március 2., kedd, 14:12:22 
> UTC+1):
>
>> Here is what I have tried.
>>
>> type product struct {
>> IDint `json:"id"`
>> Description  string  `json:"description"`
>> Price   float64  `json:"price"`
>> Bin string  `json:"bin"`
>> Qoh int  `json:"qoh"`
>> }
>> // * function to save data to a file *//
>> func saveBackup(w http.ResponseWriter, r *http.Request) {
>>
>> type Resp struct {
>> Message string `json:"message"`
>> Affected string `json:"affected"`
>> }
>> resp:= Resp{}
>>
>>
>> for k, v := range r.URL.Query() {
>> kee = k
>> val = v[0]
>> }
>> fileName :=  val // r.FormValue("filename")
>>
>> bodyBytes, err := ioutil.ReadAll(r.Body)
>>
>> var items product
>> json.Unmarshal(bodyBytes, &items)
>> fmt.Printf("%+v\n",items)
>> f, err := os.Create(fileName)
>> if err != nil {
>> fmt.Println(err)
>> return
>> }
>> l, err := f.Write(bodyBytes)
>> if err != nil {
>> fmt.Println(err)
>> f.Close()
>> return
>> }
>> fmt.Println(l, "bytes written successfully")
>> err = f.Close()
>> if err != nil {
>> fmt.Println(err)
>> return
>> }
>> resp.Message = "Save successful"
>> resp.Affected = "Saved"
>> respondWithJSON(w, http.StatusOK, resp)
>>
>> }
>>
>> // Retrieving the file ** //
>>
>> func getBackup(w http.ResponseWriter, r *http.Request) {
>>
>> kee := ""
>> fileName := ""
>> for k, v := range r.URL.Query() {
>> kee = k
>>  fileName = v[0]
>> }
>> var lines []product<=== []string  -  had this prior to scan Text
>>
>> file, err := os.Open(fileName)
>> if err != nil {
>> log.Fatal(err)
>> }
>> defer func() {
>> if err = file.Close(); err != nil {
>> log.Fatal(err)
>> }
>> }()
>>
>> // scanner := bufio.NewScanner(file)
>> //for scanner.Scan() {
>> //lines = append(lines, scanner.Text())
>> //}
>> b, err := ioutil.ReadFile(file)
>>  append(lines, b)<== I know this is wrong
>>
>> response, _ := json.Marshal(lines)
>>
>> w.Header().Set("Content-Type", "application/json")
>> w.WriteHeader(http.StatusOK)
>> w.Write(response)
>>
>> }
>>
>> How can I return the result as a JSON file to the requesting application? 
>> The client application parses the result to load into an array.
>>
>

-- 
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/ae159a92-26ae-4b49-90af-bc1511364ef6n%40googlegroups.com.


[go-nuts] I want to save a file from an incoming POST request and upon request return the file in a GET request as JSON data.

2021-03-02 Thread Hugh Myrie
Here is what I have tried.

type product struct {
IDint `json:"id"`
Description  string  `json:"description"`
Price   float64  `json:"price"`
Bin string  `json:"bin"`
Qoh int  `json:"qoh"`
}
// * function to save data to a file *//
func saveBackup(w http.ResponseWriter, r *http.Request) {

type Resp struct {
Message string `json:"message"`
Affected string `json:"affected"`
}
resp:= Resp{}


for k, v := range r.URL.Query() {
kee = k
val = v[0]
}
fileName :=  val // r.FormValue("filename")

bodyBytes, err := ioutil.ReadAll(r.Body)

var items product
json.Unmarshal(bodyBytes, &items)
fmt.Printf("%+v\n",items)
f, err := os.Create(fileName)
if err != nil {
fmt.Println(err)
return
}
l, err := f.Write(bodyBytes)
if err != nil {
fmt.Println(err)
f.Close()
return
}
fmt.Println(l, "bytes written successfully")
err = f.Close()
if err != nil {
fmt.Println(err)
return
}
resp.Message = "Save successful"
resp.Affected = "Saved"
respondWithJSON(w, http.StatusOK, resp)

}

// Retrieving the file ** //

func getBackup(w http.ResponseWriter, r *http.Request) {

kee := ""
fileName := ""
for k, v := range r.URL.Query() {
kee = k
 fileName = v[0]
}
var lines []product<=== []string  -  had this prior to scan Text

file, err := os.Open(fileName)
if err != nil {
log.Fatal(err)
}
defer func() {
if err = file.Close(); err != nil {
log.Fatal(err)
}
}()

// scanner := bufio.NewScanner(file)
//for scanner.Scan() {
//lines = append(lines, scanner.Text())
//}
b, err := ioutil.ReadFile(file)
 append(lines, b)<== I know this is wrong

response, _ := json.Marshal(lines)

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(response)

}

How can I return the result as a JSON file to the requesting application? 
The client application parses the result to load into an array.

-- 
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/9e8cb2ec-8ad7-4ae8-bd41-3558b6d4cd1bn%40googlegroups.com.