[go-nuts] Intentionally omitting requires in go.mod - alternative to multi-module repository?

2022-01-13 Thread Rodolfo Carvalho
Hello fellow Gophers!

I help maintain an SDK module
<https://pkg.go.dev/github.com/getsentry/sentry-go> that includes packages
that provide middleware to different web frameworks (e.g. echo
<https://pkg.go.dev/github.com/getsentry/sentry-go@v0.12.0/echo>).

The SDK started out as a single module in a Git repository, and we
have considered
and hesitated splitting it into multiple modules
<https://github.com/getsentry/sentry-go/issues/156> in a single repository
because of the implications that it has on maintenance, development,
testing and release processes.

The root package implements the core functionality of the SDK and has no
external dependencies, it only needs the standard library. That's what most
people need. The other packages each depend on a web framework module, and
downstream users typically only need to use one of those packages and do
not want to bother about the others.

The current `/go.mod` file is littered with dependencies to many web
frameworks
<https://github.com/getsentry/sentry-go/blob/6b72962bda2b1fb1ccc397b9d1aceb4f295606c5/go.mod>
and their dependencies, and that has caused problems and confusion to our
downstream users <https://github.com/getsentry/sentry-go/issues/376>,
especially when one of those dependencies end up flagged by tools like
Dependabot as containing a CVE. (Code security scanners seem to typically
operate on the Go module level and not at the package level, so they often
report problems even though the affected module/package is not part of the
final build list of the main package.)

I've been trying to find a way to eliminate the problems of the current
single-module-per-repo setup while avoiding the implications of going
multi-module-per-repo, as we have limited resources to maintain the SDK.

The recent idea I had was to simply omit `require` entries in the `/go.mod`
file
<https://github.com/getsentry/sentry-go/issues/156#issuecomment-1012308188>,
essentially making the module "untidy" (as in `go mod tidy` would
re-introduce the missing requires), but I haven't found any mention to
that approach on the Internet.

That idea seems hacky and possibly not conforming to the spec, but perhaps
not totally invalid.
As I read https://go.dev/ref/mod#go-mod-file and
https://go.dev/ref/mod#go-mod-file-updates, I understand that the important
`go.mod` file is the one of the main module (i.e. the `go.mod` file of our
downstream users), and as long as the main module requires the same web
framework as expected by the SDK middleware (when used), the Go tool should
be able to determine versions and complete the build.


I'd like to hear thoughts from others -- has anyone tried something similar?
Should I expect obvious problems for downstream consumers, like
failed builds?
Is there an alternative solution to be considered?

Thanks,

Rodolfo Carvalho


PS: the module graph pruning <https://github.com/golang/go/issues/36460>
from Go 1.17 <https://go.dev/doc/go1.17#go-command> has been of great help
addressing another problem of the single-module-per-repo setup, making it
such that our users that are on Go 1.17 do not need to download go.mod
files from modules they don't depend on. Many thanks to Bryan C. Mills and
the rest of the Go team!

-- 
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/CANkx08i8%2BrsprcPU5Tv7Qsg2MLx%3DV-XV%2Be5kokSQStyyP8WH%2BQ%40mail.gmail.com.


Re: [go-nuts] Data race problem with mutex protected maps

2021-06-26 Thread Rodolfo
Try to use sync.RWMutex instead, you have more control when to read or
write.

Em sáb, 26 de jun de 2021 18:34, 'Dan Kortschak' via golang-nuts <
golang-nuts@googlegroups.com> escreveu:

> On Sat, 2021-06-26 at 23:26 +0100, Rory Campbell-Lange wrote:
> > I'm trying to work out why I have a data race problem (on go 1.15 and
> > 1.16).
> >
> > *SearchResults.Set is called from several goroutines. I am trying to
> > avoid concurrent access to its two maps using a mutex, but this isn't
> > working.
> >
> > 108 type SearchResults struct {
> > 109 Boxes map[string][]Box
> > 110 seen  map[string]bool
> > 111 sync.Mutex
> > 112 }
> > 113
> > 114 // Set adds a new box to the search results map
> > 115 func (s *SearchResults) Set(b Box) {
> > 116
> > 117 s.Lock()
> > 118 defer s.Unlock()
> > 119
> > 120 if _, ok := s.seen[b.BoxID]; ok { // race problem
> > 121 return
> > 122 }
> > 123
> > 124 if model := b.GetModel(); model != "" {
> > 125 s.Boxes[model] = append(s.Boxes[model], b) // race
> > problem
> > 126 s.seen[b.BoxID] = true // race problem
> > 127 }
> > 128 }
> >
> > The data race report from go run -race  shows
> >
> > ==
> > WARNING: DATA RACE
> > Write at 0x00c12e70 by goroutine 16:
> >   runtime.mapassign_faststr()
> >   /home/rory/bin/go/src/runtime/map_faststr.go:202 +0x0
> >   main.(*SearchResults).Set()
> >   /home/rory/src/go-cex/cexer.go:126 +0x345
> > ...
> > Previous read at 0x00c12e70 by goroutine 8:
> >   runtime.mapaccess2_faststr()
> >   /home/rory/bin/go/src/runtime/map_faststr.go:107 +0x0
> >   main.(*SearchResults).Set()
> >   /home/rory/src/go-cex/cexer.go:120 +0xf6
> > ...
> > ==
> > WARNING: DATA RACE
> > Read at 0x00c12ea0 by goroutine 8:
> >   runtime.mapaccess1_faststr()
> >   /home/rory/bin/go/src/runtime/map_faststr.go:12 +0x0
> >   main.(*SearchResults).Set()
> >   /home/rory/src/go-cex/cexer.go:125 +0x195
> > ...
> > Previous write at 0x00c12ea0 by goroutine 16:
> >   runtime.mapassign_faststr()
> >   /home/rory/bin/go/src/runtime/map_faststr.go:202 +0x0
> >   main.(*SearchResults).Set()
> >   /home/rory/src/go-cex/cexer.go:125 +0x2a7
> > ...
> >
> > Advice gratefully received.
> >
> > Rory
>
> It looks like the Box type is being mutated and read in more than one
> goroutine; you're protecting Set, but is the b value being used
> elsewhen?
>
> Dan
>
>
> --
> 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/78204779089a2167f27992bad6894eaad9bd3575.camel%40kortschak.io
> .
>

-- 
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/CABjW-rx-azGuovo-tOhjgwT_J7CpVApac15XEvVth8PvPk3EpA%40mail.gmail.com.


Re: [go-nuts] Re: High Performance REST API Framework.

2020-05-09 Thread Rodolfo
I liked this:  https://gofiber.io/

For now, Its seems better to me.

Em sáb., 9 de mai. de 2020 às 18:27,  escreveu:

> Hi there,
>
> I've had quite a success with https://github.com/gin-gonic/gin, super
> fast and feels similar to lumen/laravel (php) and express (nodejs).
>
> Cheers,
> Dimitrios
>
> On Saturday, May 9, 2020 at 8:57:23 PM UTC+3, Sai Matam wrote:
>>
>> What would be a high performance web framework? I am looking for:-
>>
>>1. Reactive (non-blocking)
>>2. Enough HTTP compatibility to implement a REST API
>>3. Would be great if it feels like Spring Boot or Swagger
>>4. Well maintained.
>>5. Should be able to scale to tens of thousands of connections
>>6. WebSocket support would be nice.
>>7. idiomatic or stylized.
>>
>> Thank you.
>>
>> regards,
>> Sai Matam
>>
> --
> 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/023bc6a5-c626-427d-8f74-44e05cedbe6b%40googlegroups.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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABjW-rxWM0K4LduxZDuFb-6zwDQCg%2BsEGKPyO9tNuDTig%3DgS2g%40mail.gmail.com.


[go-nuts] Storing test cases in array of struct vs slice of struct

2019-12-23 Thread Rodolfo Carvalho
This is a question about organizing table tests.

I believe the most common idiom for writing table tests is to store test 
cases in a slice of structs like in the example from 
https://github.com/golang/go/wiki/TableDrivenTests 
<https://github.com/golang/go/wiki/TableDrivenTests#example-of-a-table-driven-test>
:

var flagtests = []struct {
in  string
out string
}{
{"%a", "[%a]"},
// ...
{"%-1.2abc", "[%-1.2a]bc"},
}

I've also seen map[string]struct{...} used when one wants to give test 
cases a name (described in detail in 
https://dave.cheney.net/2019/05/07/prefer-table-driven-tests).

What got me curious, however, are cases where instead of a slice literal, 
the author has chosen to use an array literal. Example from the Go source 
tree:

src/net/http/cookiejar/jar_test.go:var hasDotSuffixTests = [...]struct {
src/net/http/cookiejar/jar_test.go- s, suffix string
src/net/http/cookiejar/jar_test.go-}{
src/net/http/cookiejar/jar_test.go- {"", ""},
src/net/http/cookiejar/jar_test.go- {"", "."},
src/net/http/cookiejar/jar_test.go- {"", "x"},


To my surprise, the array literal pattern appears more often than maps in 
tests in the Go tree:

$ git grep -F '[]struct {' -- '*_test.go' | wc -l 
742 
$ git grep -F '[...]struct {' -- '*_test.go' | wc -l  
38 
$ git grep -F 'map[string]struct {' -- '*_test.go' | wc -l  
11 


Why and when would one put test cases in an array literal? What is the 
point?


Thank you and cheers,

Rodolfo

-- 
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/799a78ea-c9ac-40c4-9a59-163f8f3c5e58%40googlegroups.com.


[go-nuts] Re: Where is the middle of Brazil?

2019-11-30 Thread Rodolfo Azevedo
Bixo vai dormir, isso né hora pra loucura não...  hehehehehe

Em sábado, 30 de novembro de 2019 21:30:33 UTC-4, JuciÊ Andrade escreveu:
>
> When I was a kid I asked my teacher why my country capital had been moved 
> from Rio de Janeiro to Brasilia. She said the reason was Brasilia is right 
> in the middle of our territory, that way our president could take care of 
> our entire country more effectively. I accepted that answer. Many years 
> later, contemplating a map, I doubted Brasilia is right in the middle.
>
>
> Where is the middle of Brazil?
>
>
> MD5 SHA-1
>
> --
>
> 4c021557d057327f2977dd739b67da6b b3913154ca0c5f48f3555c536fc987322169e607 
> ihavetheanswer.txt
>

-- 
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/0ff45383-2d11-44f4-8f01-0e8011398d33%40googlegroups.com.


Re: [go-nuts] Golang library for - ORM & Schema Migration

2019-09-28 Thread Rodolfo
"First, nobody thinks that knowing ORM's query language absolves one from
knowing SQL."

Speak for yourself.

If you a hard spring boot user you can get into this problem.

Example:

findAll = select * from entity

This is have nothing with SQL.

findAllBySomeProperty = select * from entity where property = ?

This is have nothing with SQL.

Please, do not be rude, be honest.

Em sáb, 28 de set de 2019 00:49,  escreveu:

> First, nobody thinks that knowing ORM's query language absolves one from
> knowing SQL.
>
> But the main issue is that Go SQL interface SUCKS. It's verbose, hard to
> use and is difficult to integrate with additional tooling (try adding
> generic tracing support, I dare you!). So often your SQL code is hidden in
> reams of wrapper code that sets arguments and reads the results.
>
> So even simple ORMs that allow mapping of result sets to objects help to
> reduce boilerplate clutter. More advanced ORMs also offer simple type safe
> queries: https://github.com/go-reform/reform
>
> It's still nowhere close to LINQ for C# or http://www.querydsl.com/ for
> Java, but it's getting there.
>
> On Friday, September 27, 2019 at 3:34:59 AM UTC-7, Dimas Prawira wrote:
>>
>> Many Gophers don't like ORM as :
>> 1. ORM introduce an additional layer of abstraction that doesn't
>> accomplish anything.
>> 2. SQL syntax is more or less the same for every database.
>> 3. If you learn an ORM in Java, you will only ever able to use that ORM
>> knowledge in Java. If you learn SQL, you can use that SQL with almost
>> _exactly the same_ with any other database, and in any programming language.
>> 4. ORMs don't save you any time. The number of "lines" of code for an
>> ORM will be more or less the same as the equivalent logic done in SQL.
>>
>> But if still need to use ORM for any reasons, then you can try GORM
>> https://gorm.io/
>>
>> cheers
>>
>> On Fri, Sep 27, 2019 at 4:20 AM b ram  wrote:
>>
>>> Hi,
>>>
>>> Can you pls suggest libs for  ORM & Schema Migration.
>>>
>>> Thanks.
>>>
>>> --
>>> 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 golan...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/CAB9V516cRxPc8xuQcXQyBGXZWenv0o9ned%2BFDq2WmXyhBNm2Sg%40mail.gmail.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 on the web visit
> https://groups.google.com/d/msgid/golang-nuts/92a68ef4-9836-4d1a-8bb5-a73f0ab1d7b8%40googlegroups.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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABjW-rxMuCSqfk-riHw3Mt_rP9R2gdK3WcooL_aHh3t5YeDCXA%40mail.gmail.com.


Re: [go-nuts] Re: The performance comparation of Golang and Java

2019-01-28 Thread Rodolfo
In my poor opnion:

1. Golang is a programming language that not need a virtual machine, It
communicate directly with kernel, making use of all resource hardware
better than Java.

2. Golang uses goroutines that consume only 2k of memory instead of
2MB(minimun) of threads used in Java.

3. With Golang the dilema: "Write once run anywhere" is true, because you
can do a cross compile and run your program in differents platforms with
the same codebase.

4.  Golang offering everything do you need, without necessity to install
any framework.

And many other qualities that I do not remember :)

Regards

Rodolfo Azevedo

Em seg, 28 de jan de 2019 às 21:16, Topget  escreveu:

> It will be better if someone could give me the example(s) to show the
> advantage of Golang (vs Java). Thanks.
>
> 在 2019年1月25日星期五 UTC+8上午10:21:14,Topget写道:
>>
>> I have tested several simple functions with Golang and Java. To my
>> surprise, Java sometimes is faster than Golang(especially in recursive
>> function and some function in standard library such as math/rand.Rand). I
>> wonder why. Here is some code I used for test and the result.
>>
>> Golang code:
>>
>> package main
>>
>> import (
>> "fmt"
>> "math/rand"
>> "time"
>> )
>>
>> func calPi(pointCount int) float64 {
>> inCircleCount := 0
>>
>> var x, y float64
>> var Pi float64
>>
>> for i := 0; i < pointCount; i++ {
>> x = rand.Float64()
>> y = rand.Float64()
>>
>> if x*x+y*y < 1 {
>> inCircleCount++
>> }
>> }
>>
>> Pi = (4.0 * float64(inCircleCount)) / float64(pointCount)
>>
>> return Pi
>> }
>>
>> func fibonacci(c int64) int64 {
>> if c < 2 {
>> return c
>> }
>>
>> return fibonacci(c-2) + fibonacci(c-1)
>> }
>>
>> func main() {
>> rand.Seed(time.Now().Unix()) // 初始化随机数
>>
>> fmt.Printf("Test 1\n")
>>
>> startTime := time.Now()
>>
>> result := 0.0
>>
>> for i := 0.0; i < 10; i = i + 1 {
>> result += i * i
>> }
>>
>> endTime := time.Now()
>>
>> fmt.Printf("Result: %v\n", result)
>>
>> fmt.Printf("Duration: %v\n", endTime.Sub(startTime))
>>
>> fmt.Printf("Test 2\n")
>>
>> startTime = time.Now()
>>
>> resultInt := fibonacci(50)
>>
>> endTime = time.Now()
>>
>> fmt.Printf("Result: %v\n", resultInt)
>>
>> fmt.Printf("Duration: %v\n", endTime.Sub(startTime))
>>
>> fmt.Printf("Test 3\n")
>>
>> startTime = time.Now()
>>
>> result = 0.0
>>
>> for i := 0.0; i < 1; i = i + 1 {
>> result += rand.Float64()
>> }
>>
>> endTime = time.Now()
>>
>> fmt.Printf("Result: %v\n", result)
>>
>> fmt.Printf("Duration: %v\n s", endTime.Sub(startTime))
>>
>> fmt.Printf("Test 4\n")
>>
>> startTime = time.Now()
>>
>> result = calPi(1)
>>
>> endTime = time.Now()
>>
>> fmt.Printf("Result: %v\n", result)
>>
>> fmt.Printf("Duration: %v s\n", endTime.Sub(startTime))
>>
>> }
>>
>>
>> the result:
>>
>> Test 1
>> Result: 3.33328333552e+26
>> Duration: 1.449212507s
>> Test 2
>> Result: 12586269025
>> Duration: 1m31.645050682s
>> Test 3
>> Result: 4.999483069673434e+07
>> Duration: 2.534121566s
>>  sTest 4
>> Result: 3.14147056
>> Duration: 5.036491495s s
>>
>> Java code:
>>
>> public class Performance {
>>
>> public static double calPi(int pointCount) {
>> int inCircleCount = 0;
>>
>> double x, y;
>> double Pi;
>>
>> for (int i = 0; i < pointCount; i++) {
>> x = Math.random();
>> y = Math.random();
>>
>> if (x * x + y * y < 1) {
>> inCircleCount++;
>> }
>> }
>>
>> Pi = (4.0 * inCircleCount) / pointCount;
>>
>> return Pi;
>> }
>>
>> public static double cal(double a, double b, double c) {
>> return a * b / (c + 1) + a;
>> }
>>
>> public static long fibonacci(long c) {
>> if (c < 2)
>> return c;
>> return fibonacci(c - 2) + fibonacci(c - 1);
>> }
>>
>

Re: [go-nuts] The performance comparation of Golang and Java

2019-01-24 Thread Rodolfo
You only checking speed, you need to check memory and cpu too. Java is
faster because it allocate too much memory and If your tests during a lot
of time you will see the performance degrade, Go in other hand grow and use
less memory. My explanation is not complete, But I am a Java developer and
all system that I did with Java, when I put database driver, serialization
and etc, performs much lower than Go.

Em qui, 24 de jan de 2019 às 22:21, Topget  escreveu:

> I have tested several simple functions with Golang and Java. To my
> surprise, Java sometimes is faster than Golang(especially in recursive
> function and some function in standard library such as math/rand.Rand). I
> wonder why. Here is some code I used for test and the result.
>
> Golang code:
>
> package main
>
> import (
> "fmt"
> "math/rand"
> "time"
> )
>
> func calPi(pointCount int) float64 {
> inCircleCount := 0
>
> var x, y float64
> var Pi float64
>
> for i := 0; i < pointCount; i++ {
> x = rand.Float64()
> y = rand.Float64()
>
> if x*x+y*y < 1 {
> inCircleCount++
> }
> }
>
> Pi = (4.0 * float64(inCircleCount)) / float64(pointCount)
>
> return Pi
> }
>
> func fibonacci(c int64) int64 {
> if c < 2 {
> return c
> }
>
> return fibonacci(c-2) + fibonacci(c-1)
> }
>
> func main() {
> rand.Seed(time.Now().Unix()) // 初始化随机数
>
> fmt.Printf("Test 1\n")
>
> startTime := time.Now()
>
> result := 0.0
>
> for i := 0.0; i < 10; i = i + 1 {
> result += i * i
> }
>
> endTime := time.Now()
>
> fmt.Printf("Result: %v\n", result)
>
> fmt.Printf("Duration: %v\n", endTime.Sub(startTime))
>
> fmt.Printf("Test 2\n")
>
> startTime = time.Now()
>
> resultInt := fibonacci(50)
>
> endTime = time.Now()
>
> fmt.Printf("Result: %v\n", resultInt)
>
> fmt.Printf("Duration: %v\n", endTime.Sub(startTime))
>
> fmt.Printf("Test 3\n")
>
> startTime = time.Now()
>
> result = 0.0
>
> for i := 0.0; i < 1; i = i + 1 {
> result += rand.Float64()
> }
>
> endTime = time.Now()
>
> fmt.Printf("Result: %v\n", result)
>
> fmt.Printf("Duration: %v\n s", endTime.Sub(startTime))
>
> fmt.Printf("Test 4\n")
>
> startTime = time.Now()
>
> result = calPi(1)
>
> endTime = time.Now()
>
> fmt.Printf("Result: %v\n", result)
>
> fmt.Printf("Duration: %v s\n", endTime.Sub(startTime))
>
> }
>
>
> the result:
>
> Test 1
> Result: 3.33328333552e+26
> Duration: 1.449212507s
> Test 2
> Result: 12586269025
> Duration: 1m31.645050682s
> Test 3
> Result: 4.999483069673434e+07
> Duration: 2.534121566s
>  sTest 4
> Result: 3.14147056
> Duration: 5.036491495s s
>
> Java code:
>
> public class Performance {
>
> public static double calPi(int pointCount) {
> int inCircleCount = 0;
>
> double x, y;
> double Pi;
>
> for (int i = 0; i < pointCount; i++) {
> x = Math.random();
> y = Math.random();
>
> if (x * x + y * y < 1) {
> inCircleCount++;
> }
> }
>
> Pi = (4.0 * inCircleCount) / pointCount;
>
> return Pi;
> }
>
> public static double cal(double a, double b, double c) {
> return a * b / (c + 1) + a;
> }
>
> public static long fibonacci(long c) {
> if (c < 2)
> return c;
> return fibonacci(c - 2) + fibonacci(c - 1);
> }
>
> public static void main(String[] args) {
>
> System.out.println("Test 1");
>
> long startTime = System.currentTimeMillis();
>
> double result = 0.0;
>
> for (double i = 0.0; i < 10; i = i + 1) {
> result += i * i;
> }
>
> long endTime = System.currentTimeMillis();
>
> float duration = (float) (endTime - startTime) / 1000;
>
> System.out.println("Result: " + result);
> System.out.println("Duration: " + duration + " s");
>
> System.out.println("Test 2");
>
> startTime = System.currentTimeMillis();
>
> long resultInt = fibonacci(50);
>
> endTime = System.currentTimeMillis();
>
> duration = (float) (endTime - startTime) / 1000;
>
> System.out.println("Result: " + resultInt);
> System.out.println("Duration: " + duration + " s");
>
> System.out.println("Test 3");
>
> startTime = System.currentTimeMillis();
>
> result = 0.0;
>
> for (double i = 0; i < 1; i = i + 1) {
> result += Math.random();
> }
>
> endTime = System.currentTimeMillis();
>
> duration = (float) (endTime - startTime) / 1000;
>
> System.out.println("Result: " + result);
> System.out.println("Duration: " + duration + " s");
>
> System.out.println("Test 4");
>
> startTime = System.currentTimeMillis();
>
> result = calPi(1);
>
> endTime = System.currentTimeMillis();
>
> duration = (float) (endTime - startTime) / 1000;
>
> System.out.println("Result: " + result);
> System.out.println("Duration: " + duration + " s");
>
> }
> }
>
>
> result:
>
> Test 1
> Result: 3.33328333552E26
> Duration: 2.948 s
> Test 2
> Result: 12586269025
> Duration: 60.816 s
> Test 3
> Result: 4.087237930864E7
> Duration: 2.448 s
> Test 4
> Result: 3.14147284
> Duration: 

Re: [go-nuts] How to increase concurrent users in net/http

2019-01-14 Thread Rodolfo
Please, when you finish your workerpool can you share your code to me? I
need to understand this.

Thanks and Regards

Rodolfo Azevedo

Em seg, 14 de jan de 2019 às 10:16, Kasun Vithanage 
escreveu:

> I've deleted original post because it seems a problem with my code, will
> try to use a WorkerPool and see the result :)
> Thanks for support
>
> On Monday, January 14, 2019 at 6:38:27 PM UTC+5:30, Jesper Louis Andersen
> wrote:
>>
>> This might not be due to Go, but rather due to a resource limit imposed
>> by the operating system:
>>
>> # 5000. *. (1. -. 0.1954);;
>> - : float = 4023.
>>
>> This is close to 4096, assuming a constant factor of other stuff needing
>> resources. Also, as a first step, I'd recommend running your load generator
>> on a host separate from the system under test. There are situations in
>> which your load generator takes enough resources to mess with the SUT.
>>
>> On Mon, Jan 14, 2019 at 12:48 PM Kasun Vithanage 
>> wrote:
>>
>>> I'm doing a simple load test with Apache JMeter. My ambition was to
>>> benchmark a go server. Here is the code I've been using, its a simple web
>>> server
>>>
>>> package main
>>>
>>>
>>> import (
>>>  "fmt"
>>>  "log"
>>>  "net/http"
>>>  "runtime"
>>> )
>>>
>>>
>>> func handler(w http.ResponseWriter, r *http.Request) {
>>>  fmt.Fprintf(w, "welcome")
>>> }
>>>
>>>
>>> func main() {
>>>  runtime.GOMAXPROCS(runtime.NumCPU())
>>>  http.HandleFunc("/function", handler)
>>>  log.Fatal(http.ListenAndServe(":8080", nil))
>>> }
>>>
>>> When i test the JMeter with 5000 users with Ramp Up Period 1s, Loop
>>> Count 1 as stated below
>>>
>>> [image: Screenshot_27.png]
>>>
>>> The result is as follows, it has *around 20% error rate* for the HTTP
>>> requests.
>>>
>>> [image: Screenshot_28.png]
>>>
>>> When i examine the reason for an error JMeter states that the *Connection
>>> was refused* by host.
>>>
>>> I would like to know how to increase concurrency in here, at least not
>>> dropping the connections in that rate. If the server handler code was bit
>>> complex than this, the error rate is increasing to at least 80%.
>>>
>>> I tried the same kind of scenario with Java NIO(*com.sun.net.httpserver*).
>>> It resulted better as it had a lower error rate. But it caused a high
>>> latency when the work is done(Tested with same load).
>>>
>>> --
>>> 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.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>> --
>> J.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [go-nuts] Re: What are the reasonable reasons to use pointers?

2019-01-02 Thread Rodolfo
My simple answer is:

Using pointers you not able to copy the data.

Example:

You create a User struct and use it without point:

u := User{}

When you do this:

newUser := u you doing a copy

If the u was a pointer

newUser :=  you not doing a copy, all newUser data will be passed by
reference to u


I am not golang expert, but I think this is one possible answer.

Regards.
Rodolfo Azevedo


Em qua, 2 de jan de 2019 às 11:33, shankar shivanna 
escreveu:

>
> no idea, please help
>
> On Tuesday, 1 January 2019 17:04:34 UTC+5:30, 伊藤和也 wrote:
>>
>> What are the reasonable reasons to use pointers? Are pointers neseccary?
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [go-nuts] Is it possible to launch a Meltdown or Spectre attack with Go code?

2018-01-05 Thread Rodolfo
https://www.debian.org/security/2018/dsa-4078

2018-01-05 6:49 GMT-04:00 Wojciech S. Czarnecki :
> On Thu, 4 Jan 2018 19:35:59 -0800 (PST)
> "'Eric Johnson' via golang-nuts"  wrote:
>
>> Anyone have any insight into whether it is possible to launch a Meltdown or
>> Spectre attack using Go code?
>
> It is *not relevant* what language was used to prepare exploit. It
> always melts down to the machine code produced;
>
> The crux of both exploits is that our process' memory can be read
> by unprivileged otherwise process of other user.
>
>> On the other hand, maybe clever use of the unsafe package
>> means it is possible?
>
> Go allows for easy asm so it is possible IMO to write an exploit
> using Go tools. Not relevant though.
>
>> Eric.
>>
>
> --
> Wojciech S. Czarnecki
>  << ^oo^ >> OHIR-RIPE
>
> --
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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


Re: [go-nuts] NullTime in sql package ?

2017-12-10 Thread Rodolfo
I prefer to work with milliseconds, this is suitable in any language,
os and applications.

2017-12-10 17:26 GMT-04:00 Liviu G :
> Does anyone know why we don't have a NullTime like NullString in
> database/sql package ?
> We shouldn't need to copy/paste this code in various projects
> or depend on the driver specific NullTime (for postgres for example), right
> ?
>
> type NullTime struct {
>
> time.Time
>
> Valid bool
>
> }
>
>
> func (this *NullTime) Scan(value interface{}) error {
>
> this.Time, this.Valid = value.(time.Time)
>
> return nil
>
> }
>
>
> func (this NullTime) Value() (driver.Value, error) {
>
> if !this.Valid {
>
> return nil, nil
>
> }
>
> return this.Time, nil
>
> }
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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


Re: [go-nuts] Easiest way to work with database

2017-10-21 Thread Rodolfo
Vickey,

you can work with timestamps, to me is the easiest way to work with
time data in any language and framework, because always an Int value
:D

Good Luck!

2017-10-21 21:35 GMT-04:00  :
> HiShawn,
>
> I just want to know say i have a test table in postgres. With 2 column one 
> date and another string.i want to create an HTML table which can be updated 
> and deleted by a click.
>
> Like
>
>
> Time| string
> X:xx| xyz update delete
> X:xx| xyz update delete
> X:xx| xyz update delete
> X:xx| xyz update delete
>
> Something like this i am not able to find out how to save the time data in a 
> slice. Or should i use a struct or a slice of struct. Nothing works.
>
>
> Can you please guide me how to do it.don't write the code just the steps. I 
> couldn't find it on net.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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


Re: [go-nuts] Choosing a framework

2017-09-09 Thread Rodolfo
https://echo.labstack.com/

2017-09-09 19:51 GMT-04:00 Tim Uckun :

> I am in the process of learning go and decided to do it by writing a
> (mostly) API based web site. I have been doing some research and have found
> the following.
>
> Revel: https://revel.github.io/
> GoBuffalo: https://gobuffalo.io/
> Iris: https://iris-go.com/
>
> In addition there are "toolkits" like chi and buffallo but it looks like
> eventually I will need pretty much all the things these frameworks provide
> and there are so many competing projects that provide logging,
> configuration, routing, middleware etc that it would take me a long time to
> do all the research and find the ones most suitable for me.
>
> I understand that there is quite a bit of controversy with iris so I
> probably won't go with that one but does anybody have any experience with
> the others they are willing to share?
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [go-nuts] Connect to a mainframe

2017-03-28 Thread Rodolfo
Hi, not work for me, show this error:

package ibm.com/mainframe: unrecognized import path "ibm.com/mainframe"

Can you help me?

Thanks

2017-03-28 18:03 GMT-04:00 Aram Hăvărneanu :

> go get ibm.com/mainframe
>

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


Re: [go-nuts] Connect to a mainframe

2017-03-28 Thread Rodolfo
Thanks for fast answer :D

2017-03-28 18:03 GMT-04:00 Aram Hăvărneanu :

> go get ibm.com/mainframe
>

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


[go-nuts] Connect to a mainframe

2017-03-28 Thread Rodolfo Azevedo
Someone has an example to how to connect to a mainframe? I am searching in 
the web and not found.

Thanks and regards,


Rodolfo Azevedo

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


[go-nuts] Re: NewTicker function example

2017-02-22 Thread Rodolfo Azevedo
You can use sync WaitGroup too

https://play.golang.org/p/bb3a6t1N-C

But WILL NOT WORK ON playground, because of limitations of time package on 
playground.

Regards.

Em quarta-feira, 22 de fevereiro de 2017 21:39:12 UTC-4, Keith Brown 
escreveu:
>
> Oddly, I can't find a single example on the world wide web for what I am 
> trying to do.
>
> I have 2 functions which I want to run on a periodic basis. The functions 
> are square and cube. 
> Here is my code so far. https://play.golang.org/p/akMxcg2Sra
> But, I am not sure how to schedule these functions.  I looked here, 
> https://gobyexample.com/tickers, but really isn't that helpful or 
> intuitive. 
>
>
>
>

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


[go-nuts] Re: NewTicker function example

2017-02-22 Thread Rodolfo Azevedo
Like this?

https://play.golang.org/p/rXPl7Bco0c

Em quarta-feira, 22 de fevereiro de 2017 21:39:12 UTC-4, Keith Brown 
escreveu:
>
> Oddly, I can't find a single example on the world wide web for what I am 
> trying to do.
>
> I have 2 functions which I want to run on a periodic basis. The functions 
> are square and cube. 
> Here is my code so far. https://play.golang.org/p/akMxcg2Sra
> But, I am not sure how to schedule these functions.  I looked here, 
> https://gobyexample.com/tickers, but really isn't that helpful or 
> intuitive. 
>
>
>
>

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


[go-nuts] Re: HTTP Server - Force close connection after response

2017-01-16 Thread Rodolfo Azevedo
You can use defer:

defer bufrw.Flush()
defer conn.Close()

It will close after method finishs, but I do not know if it will work for 
you because you using go routines to start server, I never see this, I 
always use:

log.Fatal(http.ListenAndServe(":8080", mux))


Well, I think you can try.


Em segunda-feira, 16 de janeiro de 2017 23:36:27 UTC-4, Tony Grosinger 
escreveu:
>
> I would like to create an HTTP server which forces the connection to be 
> closed after writing the response.
> For example:
>
> func closingHandler(w http.ResponseWriter, r *http.Request) {
> // Respond before hijacking?
> fmt.Fprintf(w, "Hello World")
>
> hj, ok := w.(http.Hijacker)
> if !ok {
> log.Println("Unable to create hijacker")
> return
> }
>
> conn, bufrw, err := hj.Hijack()
> if err != nil {
> log.Println("Unable to hijack request")
> return
> }
>
> bufrw.Flush()
> conn.Close()
> }
> func main() {
> mux := http.NewServeMux()
> mux.HandleFunc("/", closingHandler)
>
> go func() {
> err := http.ListenAndServe(":8080", mux)
> if err != nil {
> log.Println("Failed to run server"
> }
> }()
> }
>
> This example does not work however because the client issuing the request 
> cannot successfully read the response. Is there another way to close the 
> connection manually that would allow me to respond to the HTTP request 
> first?
> ​
>

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


[go-nuts] Why is ioutil.Discard implemented using an int and not an empty struct?

2016-10-17 Thread Rodolfo Carvalho
Hi,

I noticed that when io.Discard was introduced in
https://codereview.appspot.com/4426066/, it replaced code like:

type devNull struct{}


With:


type devNull int


Both had the very same implementation of the Write method:

func (devNull) Write(p []byte) (int, os.Error) {
 return len(p), nil
}



What's the advantage of using an int in this case, if any?


Thank you,

Rodolfo Carvalho

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


Re: [go-nuts] image: algorithm to convert to grayscale

2016-09-29 Thread Rodolfo Carvalho
Thanks everyone for the answers and links.

I computed a pixel-to-pixel difference and indeed what I was getting was
-1/+1 differences in the gray values, due to rounding.

Next free time I'll try the other formulas.


Thank you again,

Rodolfo Carvalho

On Thu, Sep 29, 2016 at 6:12 AM, Micky <mickylmar...@gmail.com> wrote:

>
>
> On Thu, Sep 29, 2016 at 3:19 AM, Rodolfo Carvalho <rhcarva...@gmail.com>
> wrote:
>
>> gift [3]:
>> y := 0.299*px.R + 0.587*px.G + 0.114*px.B
>>
>> I did not understand why image/color adds an extra 0.5 (500/1000) to y.
>> Could anybody give me a clue?
>>
>
> To directly answer your question:
>
> *GIFT also adds 0.5 to round off. *
>
> Wanna know where? Try to make up a call stack:
>
> gift.Grayscale() > returns Filter > is colorFilter > has a callback fn >
> returns pixel > contains float32s
>
> pixel is a struct containing float32s
> Filter is an interface, made of Draw() and Bounds()
> colorFilter implements Filter
>
> So, it eventually boils down to: [1]
>
> *colorFilter.Draw() > parallelize() > newPixelSetter().SetPixel() >
> f32u16()
>
> color.Color uses uint32s while gift.pixel uses float32s. I guess gift uses
> floats for cosmetic reasons. But they both round off while applying the
> grayscale filter.
>
> [1] https://github.com/disintegration/gift/blob/
> 703be73d60d8baeaa84c47be0d31551b466ea84a/pixels.go#L304
>
>
>
>
>

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


[go-nuts] image: algorithm to convert to grayscale

2016-09-28 Thread Rodolfo Carvalho
Hello,

I'm not an image processing expert, but was trying to write a small program
to convert images to grayscale, just for the fun of it [1].

First I managed to get something working with image/draw, then I
discovered about github.com/disintegration/gift through an old post here.

I realized the output images had a different luminance, what led me to dig
a bit deeper to see how the implementations differed.


image/color [2]:

y := (299*r + 587*g + 114*b + 500) / 1000


gift [3]:

y := 0.299*px.R + 0.587*px.G + 0.114*px.B


The initially funny numbers, weights, match those described in Wikipedia
[4].
I went ahead and compared to what Matlab [5] and Octave [6] do and found a
similar formula.


I did not understand why image/color adds an extra 0.5 (500/1000) to y.
Could anybody give me a clue?




[1] https://gist.github.com/rhcarvalho/5e97f310701528f5a0610415e317b992
[2] image/color:
https://github.com/golang/go/blob/master/src/image/color/color.go#L249
[3] GIFT: https://github.com/disintegration/gift/blob/master/colors.go#L252
[4] https://en.wikipedia.org/wiki/Grayscale#Luma_coding_in_video_systems
[5] Matlab:
https://www.mathworks.com/help/matlab/ref/rgb2gray.html#expand_body_buiz8mj-9
[6] Octave:
https://sourceforge.net/p/octave/image/ci/default/tree/inst/rgb2gray.m#l43


Thanks,

Rodolfo Carvalho

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


[go-nuts] Re: how to restrict the program run only one instance

2016-09-17 Thread Rodolfo Amaral
I know this topic is a bit old, but I needed it recently on Windows and 
I'll post here how I did it in case someone else needs.

I used Windows mutex as described by ankurg...@gmail.com:

var (
kernel32= syscall.NewLazyDLL("kernel32.dll")
procCreateMutex = kernel32.NewProc("CreateMutexW")
)

func CreateMutex(name string) (uintptr, error) {
ret, _, err := procCreateMutex.Call(
0,
0,
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(name))),
)
switch int(err.(syscall.Errno)) {
case 0:
return ret, nil
default:
return ret, err
}
}

// mutexName starting with "Global\" will work across all user sessions
_, err := CreateMutex("SomeMutexName")

I created a lib with a more complete example: 
https://github.com/rodolfoag/gow32

Thx!

Em sábado, 4 de junho de 2016 11:30:14 UTC-3, ankurgu...@gmail.com escreveu:
>
> The simplest solution would be to do it using MUTEX, here is how to do it 
> 
>  along 
> with description.
>
> On Wednesday, 22 January 2014 09:22:34 UTC+5:30, Shark Flh wrote:
>>
>> how to restrict the program run only  one instance
>> what method can work on windows and Linux both system?
>>
>> for example I have a program test.exe, I copy it to 2 dir
>> a/test.exe
>> b/test.exe
>> I want  restrict the test.exe can only run one instance from each dir.
>>
>> i tried open  file use ModeExclusive,but it doesn't on windows.
>>
>>

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