[go-nuts] add guru support refer folder outside gopath

2019-08-15 Thread hui zhang
"Find All References" does not find code in other packages outside 
GOPATHin vscode

https://github.com/microsoft/vscode-go/issues/2236
https://github.com/Microsoft/vscode-go/issues/1602
https://github.com/Microsoft/vscode-go/issues/1473

the root cause is that guru did not support that.
as guru is part of the official tool. 
pls add feature,  
guru support refer folder outside gopath.
the folder could be project root path


-- 
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/dbb85d34-2b09-4727-b007-ac469bb5819b%40googlegroups.com.


Re: [go-nuts] Proposal: provide runtime sigprocmask api to block some signal for go runtime

2019-08-14 Thread hui zhang

thanks
I found a way throungh.
dynamic load so dlopen("go.so")  in main function after pthread_sigmask
this let go runtime start after father thread , and have the same sigmask.

-- 
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/1e8b13d4-54ba-4aaa-ac5f-283e4497cd2a%40googlegroups.com.


[go-nuts] Proposal: provide runtime sigprocmask api to block some signal for go runtime

2019-08-13 Thread hui zhang
check this  https://groups.google.com/forum/#!topic/golang-nuts/1YvP-5V6xSI
when we code golang with c,   some c code used *  sigwait  sigwaitinfo* 
function to wait signal.
sometime this signal is caught by golang runtime,  and this cause cash.
we want the signal continue to be handled by *sigwait  sigwaitinfo*


-- 
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/086f1e16-c8ea-4970-b4e8-98b34c4dec75%40googlegroups.com.


Re: [go-nuts] how cgo handle user define signal ? need go pass the signal handle to c

2019-08-13 Thread hui zhang

in other words
we need a *go runtime signal mask .*
just google, no such api provided by go yet .
I want know why ?
any workaround?

-- 
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/fcdceef3-6bcc-46cc-bf37-004b379c70bc%40googlegroups.com.


Re: [go-nuts] how cgo handle user define signal ? need go pass the signal handle to c

2019-08-13 Thread hui zhang
I found the case is like this
c code
IgnoreSignal(42);
while(1) {
GoSleep(10);//simulate some call in go runtime , the runtime call stack is
in last mail
int signo = sigwaitinfo(_set, _info); //will use this signo
to do something 
// usleep(1000*1000);
printf("sleep 10s \n");
// raise(42);
}

go code
//export IgnoreSignal
func IgnoreSignal(sig int) {
signal.Ignore(syscall.Signal(sig))
}

//export GoSleep
func GoSleep(x int) {
time.Sleep(time.Duration(x) * time.Second)
}

go build an  so lib ,  c link this so
run app
send signal like below
sigqueue(pid, 42, val);

go will catch that signal ,  and  but ignore it and delete it
what I expect  is passing the signal to  *sigwaitinfo*

hui zhang  于2019年8月13日周二 上午9:58写道:

> I am trying to extend a old c program with go.Add websocket ability to
> this c program.
> first  build  go as a  .so  dynamic lib
> then link the so lib in c program
> I run the cgo ok in an example program.
> But when integrate with old c program,  c program will send a signal 42 to
> itself periodly.
> this cause so lib terminate
>
> rogram received signal SIG42, Real-time event 42.
> [Switching to Thread 0xa53c6b70 (LWP 14957)]
> runtime.futex () at /usr/local/go/src/runtime/sys_linux_386.s:444
> 444 /usr/local/go/src/runtime/sys_linux_386.s: No such file or directory.
> in /usr/local/go/src/runtime/sys_linux_386.s
> Missing separate debuginfos, use: debuginfo-install WBXcms-3.7.0-494.i686
> (gdb) bt
> #0 runtime.futex () at /usr/local/go/src/runtime/sys_linux_386.s:444
> #1 0xb7b04c2a in runtime.futexsleep (addr=0xb7fa47ac, val=0, ns=-1) at
> /usr/local/go/src/runtime/os_linux.go:46
> #2 0xb7ae5437 in runtime.notesleep (n=0xb7fa47ac) at
> /usr/local/go/src/runtime/lock_futex.go:151
> #3 0xb7b0c8f4 in runtime.stopm () at /usr/local/go/src/runtime/proc.go:1936
> #4 0xb7b0d848 in runtime.findrunnable (gp=@0x74421300, inheritTime=@0x0)
> at /usr/local/go/src/runtime/proc.go:2399
> #5 0xb7b0e507 in runtime.schedule () at
> /usr/local/go/src/runtime/proc.go:2525
> #6 0xb7b0edac in runtime.goexit0 (gp=0x744000e0) at
> /usr/local/go/src/runtime/proc.go:2722
> #7 0xb7b2f868 in runtime.mcall () at
> /usr/local/go/src/runtime/asm_386.s:345
> #8 0xb7b2f7c0 in runtime.rt0_go () at
> /usr/local/go/src/runtime/asm_386.s:241
> #9 0xb7b2f7c7 in runtime.rt0_go () at
> /usr/local/go/src/runtime/asm_386.s:246
> #10 0x00
>
> My question is
> *how go so lib ignore this signal 42,  and pass the signal handle to old c
> program.*
>
> Thanks
>
> --
> 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/1YvP-5V6xSI/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/22745e49-1d43-4e3a-9d78-20ff6bb20d4e%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/22745e49-1d43-4e3a-9d78-20ff6bb20d4e%40googlegroups.com?utm_medium=email_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/CAF7uC_vecUj34DuYteEARMxanWNvGxMT_pWj%3DLjCz7OigFPtvw%40mail.gmail.com.


[go-nuts] how cgo handle user define signal ? need go pass the signal handle to c

2019-08-12 Thread hui zhang
I am trying to extend a old c program with go.Add websocket ability to 
this c program.
first  build  go as a  .so  dynamic lib
then link the so lib in c program
I run the cgo ok in an example program.
But when integrate with old c program,  c program will send a signal 42 to 
itself periodly. 
this cause so lib terminate 

rogram received signal SIG42, Real-time event 42.
[Switching to Thread 0xa53c6b70 (LWP 14957)]
runtime.futex () at /usr/local/go/src/runtime/sys_linux_386.s:444
444 /usr/local/go/src/runtime/sys_linux_386.s: No such file or directory.
in /usr/local/go/src/runtime/sys_linux_386.s
Missing separate debuginfos, use: debuginfo-install WBXcms-3.7.0-494.i686
(gdb) bt
#0 runtime.futex () at /usr/local/go/src/runtime/sys_linux_386.s:444
#1 0xb7b04c2a in runtime.futexsleep (addr=0xb7fa47ac, val=0, ns=-1) at 
/usr/local/go/src/runtime/os_linux.go:46
#2 0xb7ae5437 in runtime.notesleep (n=0xb7fa47ac) at 
/usr/local/go/src/runtime/lock_futex.go:151
#3 0xb7b0c8f4 in runtime.stopm () at /usr/local/go/src/runtime/proc.go:1936
#4 0xb7b0d848 in runtime.findrunnable (gp=@0x74421300, inheritTime=@0x0) at 
/usr/local/go/src/runtime/proc.go:2399
#5 0xb7b0e507 in runtime.schedule () at 
/usr/local/go/src/runtime/proc.go:2525
#6 0xb7b0edac in runtime.goexit0 (gp=0x744000e0) at 
/usr/local/go/src/runtime/proc.go:2722
#7 0xb7b2f868 in runtime.mcall () at /usr/local/go/src/runtime/asm_386.s:345
#8 0xb7b2f7c0 in runtime.rt0_go () at 
/usr/local/go/src/runtime/asm_386.s:241
#9 0xb7b2f7c7 in runtime.rt0_go () at 
/usr/local/go/src/runtime/asm_386.s:246
#10 0x00

My question is 
*how go so lib ignore this signal 42,  and pass the signal handle to old c 
program.*

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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/22745e49-1d43-4e3a-9d78-20ff6bb20d4e%40googlegroups.com.


Re: [go-nuts] how to pass c array to golang efficiently

2019-08-07 Thread hui zhang
Got it, thanks!

Jan Mercl <0xj...@gmail.com> 于2019年8月7日周三 下午4:20写道:

> On Wed, Aug 7, 2019 at 3:17 AM hui zhang  wrote:
>
> > //export Send
> > func Send(confid string, len int, pcm *C.short) {
> >//put c.short array to int16 slice/array efficiently , how ?
> >// memcopy ?
> > }
>
> s := (*[^uint(0) >> 1]int16)(unsafe.Pointer(pcm))[:len] // s is
> []int16, len(s) = len
>

-- 
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/CAF7uC_vQZDFwdzyVEO%2BxxMt67Vk8BkH%3DkK%3DsRLFWLFaiVKBkFA%40mail.gmail.com.


[go-nuts] how to pass c array to golang efficiently

2019-08-06 Thread hui zhang
I build go as a so called by c program
how implement this Send function to make c  short array to be used in go as 
[]int16 
*efficiently *
of course ,  I can assign it one by one , but it is not an efficient way

package main

import "C"
import "fmt"

//export Summ
func Summ(x, y int) int {
   return x + y
}

//export Hello
func Hello(str string) {
   fmt.Printf("Hello: %s\n", str)
}

//export Send
func Send(confid string, len int, pcm *C.short) {
   //put c.short array to int16 slice/array efficiently , how ?
   // memcopy ?
}

func main() {
   // We need the main function to make possible
   // CGO compiler to compile the package as C shared/archive library
}


go build -buildmode=c-shared -o ws.so ws.go

#include 
#include "ws.h"

int main()
{
printf("This is exptest application.\n");
GoString str = {"Hi JXES", 7};
Hello(str);
printf("sum: %lld\n", Summ(2, 3));

short a[] = {1,2,3,4,5,6};
Send(str,6,a);
return 0;
}


gcc -o cms cms.c ws.so



-- 
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/1630397c-79f8-4f25-b855-d6a9f7cdf506%40googlegroups.com.


Re: [go-nuts] Re: is there a goroutine scope global veriable ?

2019-06-19 Thread hui zhang
this implement does not solve the problem.
still need pass the parameter in all functions. 
func (g *gls) run()orfunc run (g *gls) 

在 2019年6月19日星期三 UTC+8下午4:55:09,Jan Mercl写道:
>
> On Wed, Jun 19, 2019 at 10:41 AM hui zhang  > wrote: 
>
> > but, very few document mention , how to do it as goroutine local storage 
> .  Can anyone give an example to solve my problem , refer the code I 
> attached? 
>
> Make the goroutine a method of a struct that contains any context the 
> goroutine needs. The data in the struct becomes your goroutine-local 
> storage. 
>
> type gls struct { id int } 
>
> func newG(id int) { 
> g := {id} 
> go g.run() 
> } 
>
> func (g *gls) run() { fmt.Println(g.id) } 
>

-- 
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/35de6b92-8240-4892-bc2e-d5cda3980582%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: is there a goroutine scope global veriable ?

2019-06-19 Thread hui zhang
thank you very much.  
Is there a  golang context way to do it?

在 2019年6月19日星期三 UTC+8下午4:55:09,Jan Mercl写道:
>
> On Wed, Jun 19, 2019 at 10:41 AM hui zhang  > wrote: 
>
> > but, very few document mention , how to do it as goroutine local storage 
> .  Can anyone give an example to solve my problem , refer the code I 
> attached? 
>
> Make the goroutine a method of a struct that contains any context the 
> goroutine needs. The data in the struct becomes your goroutine-local 
> storage. 
>
> type gls struct { id int } 
>
> func newG(id int) { 
> g := {id} 
> go g.run() 
> } 
>
> func (g *gls) run() { fmt.Println(g.id) } 
>

-- 
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/62562359-5c78-4053-b2e4-1defe6ebdb8a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: is there a goroutine scope global veriable ?

2019-06-19 Thread hui zhang
thanks ,  I also google blew links.
It is called goroutine local storage (gls)  and  many third party 
implement(https://github.com/jtolds/gls)
however,   the golang official suggest to use go context.
but, very few document mention , how to do it as goroutine local storage .  
Can anyone give an example to solve my problem , refer the code I attached?


在 2019年6月19日星期三 UTC+8上午11:03:59,Kurtis Rader写道:
>
> On Tue, Jun 18, 2019 at 7:56 PM hui zhang  > wrote:
>
>>
>> is there a goroutine scope global veriable ?   so  I can do this ?
>>
>
> You're asking if Go supports the equivalent of thread local storage as 
> used in Java, C++, and Python. The answer is, no. See 
> https://stackoverflow.com/questions/31932945/does-go-have-something-like-threadlocal-from-java
>  and https://github.com/golang/go/issues/21355 
> <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fgolang%2Fgo%2Fissues%2F21355=D=1=AFQjCNELmaTzdMd_Zeyro6a5KDMC9HO6Sg>
>
> -- 
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>

-- 
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/a06da5ca-4967-4697-bfbe-e043a838844d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: is there a goroutine scope global veriable ?

2019-06-18 Thread hui zhang
is there a goroutine scope global veriable ?
like  fork a variable from main ?

-- 
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/d656aafc-d9df-4553-92ac-230a46ba86b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: is there a goroutine scope global veriable ?

2019-06-18 Thread hui zhang

is there a goroutine scope global veriable ?   so  I can do this ?

-- 
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/b76b0ec7-dd59-4410-9177-3596d5733fb4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] is there a goroutine scope global veriable ?

2019-06-18 Thread hui zhang
I write logs into one single log file.
and need to set a different tracking id for each goroutine.
But I don't want to pass the tracking id argument for all functions.


func main() {
  go Func()
}
func Func() {
  SetLogTrackId("")
  LogDebug("123")
  call1()
}
func call1() {
   LogDebug("call1")
}
var trackId string //need this scope to be goroutine scope
func SetLogTrackId(id string) {
trackId = id
}
func LogDebug(v ...interface{}) {
log.Println("DEBUG " + trackId + " " + fmt.Sprintln(v...))
}


-- 
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/798a4565-5f1c-4495-8589-3575ba52953a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] how to test main function coverage with different args

2019-04-23 Thread hui zhang
how to test main function coverage with different args  to  enhance 
coverage rate
how to cover the red part ? for you can set args once a time

func Test_main(m *testing.T) {
   main2()
}


go test -coverprofile coverage.cov -args xxx.conf go tool cover 
-html=coverage.cov -o coverage.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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] how to go test a daemon process

2019-04-23 Thread hui zhang


I have daemon process,  I try to test its coverage


func Test_main(m *testing.T) {
   main()
}

go test -coverprofile coverage.out -args xxx.conf

since it is a daemon,  I have to kill it to stop it
kill   or   ctrl  +  c


I got the coverage report  coverage.out  only 10B


and of course ,  no  coverage report when run 

go tool cover -html=coverage.out -o coverage.html



how to solve this problem?

-- 
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] Is there a way to force to pass some function or error check when Debugging?

2019-04-22 Thread hui zhang
I am debugging a linux server program in local mac machine.
some code related to environment check , such as check mount point etc.

I want to pass this check ,   how ?

   - I try it set return error var to nil.  but it seems not working in 
   devel for now.
   - I imagine to mock function, but not sure how to do it when debugging.
   - I knew the convenient way is to change source code directly .   But 
   there is a lot of code to change .  I don't want to mess it up
   
any advice?

-- 
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] go test cover on other platforms

2019-04-11 Thread hui zhang
I am developing go on mac
but my test environment is on linux.

Can I build a bin like 
GOOS=linux GOARCH=amd64 go test -c && ./sum.test

and do test on linux , and get a coverage report ?
how?

Need install go environment on linux ?

-- 
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] go test cover with args, coverage flag has been treat like an args.

2019-04-11 Thread hui zhang
my program take 4 args like  
./myprogram   1 2 3 4
*args_len=: 5*
I want to test this program coverage so  
go test -coverprofile coverage.out  -args 1 2 3 4

myprogram_test.go

func Test_main(m *testing.T) {
   main()

}


DEBUG  args= 
[/var/folders/cp/561_gl9j1wzd8dgv_fn5mk7cgn/T/go-build225076203/b001/myprogram.test
 
-test.coverprofile=/var/folders/cp/561_gl9j1wzd8dgv_fn5mk7cgn/T/go-build225076203/b001/_cover_.out
 
1 2 3 4]
ERROR  invalid *args_len=: 6*

the coverage flag has been add to args   cause program error,   invalid 
args_len=: 6   
How to resolve this ?

-- 
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] how to build golang program with a lower kernel requirement?

2018-11-29 Thread hui zhang
I build golang programe on ubuntu 18.04, try to run it on ubuntu 16.04 , it 
hint "kernal too old"

ldd --version ldd (Ubuntu GLIBC 2.27-3ubuntu1) 2.27 #ubuntu 18.04 ldd 
(Ubuntu GLIBC 2.23-3ubuntu1) 2.23 #ubuntu 16.04
glibc 2.24 above requires kernel 3.2 minimum glibc 2.23 requires kernel 
2.6.32. minimum #ubuntu 16.04

Q1:
how to build golang program with a lower kernel requirement?

Q2:
on the other hand 
if I build golang program on ubuntu 16.04 ,  can it run on ubuntu 18.04

-- 
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: different behaviour in return: error is shadowed during return

2018-11-27 Thread hui zhang
happen in  go 1.10.2   1.11.2

在 2018年11月28日星期三 UTC+8上午11:02:47,hui zhang写道:
>
> ./main.go:212:4: err is shadowed during return
>
> check code above only line 212 report err 
> however line 203 and 212 are almost the same case. but did not report err.
>

-- 
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] different behaviour in return: error is shadowed during return

2018-11-27 Thread hui zhang
./main.go:212:4: err is shadowed during return

check code above only line 212 report err 
however line 203 and 212 are almost the same case. but did not report err.

-- 
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 there a way or lib to read a binary into a sturct{len int32;data [len]int32}

2017-11-14 Thread hui zhang
I found what I want
https://github.com/lunixbochs/struc
https://github.com/go-restruct/restruct

2017-11-07 18:33 GMT+08:00 Konstantin Khomoutov <kos...@bswap.ru>:

> On Tue, Oct 31, 2017 at 04:36:20PM +0800, hui zhang wrote:
>
> [...]
> > > > Is there a way or lib to read a binary into a this structure in one
> line
> > > > code?
> > > >
> > > > how about more complicate struct ?
> > > > type complicatestrt struct {
> > > >   len int32
> > > >   strData []variastrt
> > > > }
> [...]
> > > - Write some complicated code which uses reflection -- just like
> > >   the stock encoding/binary does -- to understand how to interpret the
> > >   fields of any custom struct type based on that type's tags (or just
> > >   "shape" -- that is, the types and relative order of its fields).
> > >
> > > For the latter, take into account that while there's no mention of the
> > > format of the field tag in the language spec, the convention for their
> > > format is documented at [4]:
> > >
> > > | By convention, tag strings are a concatenation of optionally
> > > | space-separated key:"value" pairs. Each key is a non-empty string
> > > | consisting of non-control characters other than space (U+0020 ' '),
> > > | quote (U+0022 '"'), and colon (U+003A ':'). Each value is quoted
> using
> > > | U+0022 '"' characters and Go string literal syntax.
> > >
> > > Hence you could come up with something like:
> > >
> > >   type variastrt struct {
> > >   len  int32   `var:"value:data endian:big"`
> > >   data []int32 `var:"endian:little"`
> > >   }
> > >
> > > And then you'd reflect over the type the user supplied to your
> > > unmarshaling code, and in that reflection code you'd parse the field's
> > > tag, get the value associated with the "var" key and parse that, in
> > > turn, to know the name of the field to unmarshal the value into, and
> the
> > > endianness of the elements of that value (if applicable).
> [...]
> > > 4. https://golang.org/pkg/reflect/#StructTag
>
> > Thank you very much
> > I know something like below could do.  The problem has some one did it ?
> I
> > don't know how to use the tag string.
> >  type variastrt struct {
> >   len  int32   `var:"value:data endian:big"`
> >   data []int32 `var:"endian:little"`
> >   }
>
> I'm not sure what you're asking about.
> As I have said, if you would like to implement the indicated approach,
> you would need to write code which obtains tags defined on the fields of
> a user-programmed type, parses them and acts based on the results.
>
> I have shown you what is the codified policy on the format of the struct
> field tags (they are not defined by the Go language specification but
> everyone agrees upon that policy which I cited in my first reply to this
> thread).  To inspect at runtime the type of a user-supplied variable,
> and then further inspect its properties — such as fields of a struct
> type, you need to use the standard package "reflect".
>
> If you want to learn how to reflect over any custom user-defined type
> using the standard package "reflect" and deal with the tags defined on
> the fields of such a type, I'd suggest looking at the standard package
> encoding/json and encoding/xml which make heavy use of these tags.
>
> --
> 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/Nn5ZuGIXDUM/unsubscribe.
> To unsubscribe from this group and all its topics, 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.


[go-nuts] Is there a way or lib to read a binary into a sturct{len int32;data [len]int32}

2017-10-30 Thread hui zhang
type variastrt struct {
len int32
data []int32  //  data length = len   [len]int32
}

Is there a way or lib to read a binary into a this structure in one line 
code?

how about more complicate struct ?
type complicatestrt struct {
  len int32
  strData []variastrt
}

-- 
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] go/mobile: is it possible to publish go build ios app on appstore?

2017-05-03 Thread hui zhang

Here is a document to show how to publish go build app on google play
https://pt.slideshare.net/takuyaueda967/go-for-mobile-games

However ,  there is no document on how to publish go build app on app store

how to do this,  is it possible ?
And it is much easier to integrate ios framework than jar pakcage.

-- 
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: How let go and c code work Alternately in the same thread

2017-04-28 Thread hui zhang
The different framework decide c/go have to be in different loop ,,a c
loop and a go loop.
It is hard to change that,

2017-04-28 16:17 GMT+08:00 <djad...@gmail.com>:

>
>
> On Friday, April 28, 2017 at 9:18:03 AM UTC+3, hui zhang wrote:
>>
>> How let go and c code work Alternately in the same thread with
>> goroutine(corouting mechanism)
>> Check the code below.  c and go code in one thread they just do work 1 by
>> 1.
>> Expected Result
>>
>>> Do CWork
>>> Do GoWork
>>> Do CWork
>>> Do GoWork
>>> Do CWork
>>> .
>>
>>
>> //c code
>>> void CWork() {
>>> while(1) {
>>>--Print Do CWork
>>>--Coroutine Stop
>>> --switch to GoWork()
>>> }
>>> }
>>> int main() {
>>> CWork();
>>> }
>>> //go code
>>> func GoWork() {
>>> for {
>>> --Print Do GoWork
>>>--Coroutine Stop
>>> --switch back to CWork()
>>> }
>>> }
>>
>>
>>
>>
>
>
> Hi, simplest solution:
>
> //c code
>> void CWork() {
>> --Print Do CWork
>> }
>> int main() {
>> for {
>> C.CWork()
>> GoWork()
>> }
>> }
>>
>> //go code
>> func GoWork() {
>> --Print Do GoWork
>> }
>
>
>
>  Djadala
>
> --
> 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/Yaay2_UaIxU/unsubscribe.
> To unsubscribe from this group and all its topics, 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: How let go and c code work Alternately in the same thread

2017-04-28 Thread hui zhang
I tried ,  it is *not* in the same thread.   if cwork and gowork call
thread-unsafe api,  it will crash

package main

// #include 
import "C"
import (
   _ "fmt"
   "time"
   "runtime"
)

var go_done = make(chan bool, 1)
var c_done = make(chan bool, 1)

func init() {
   runtime.GOMAXPROCS(1)
   //runtime.LockOSThread()
}

func GoWork() {
   //runtime.LockOSThread()
   println("GoWork thread=", C.pthread_self())
   go_done <- true
   for {
  <-c_done
  println("c done, now go thread=",C.pthread_self())
  time.Sleep(time.Second)
  go_done <- true
   }

}

func main() {}

//export Start
func Start() {
   //runtime.LockOSThread()
   println("C Start thread=", C.pthread_self())
   go GoWork()
   //for {
   // <-go_done
   // println("go done, now c wokr")
   // time.Sleep(time.Second)
   // c_done <- true
   //}
}

//export CWork
func CWork() {
   <-go_done
   println("go done, now c thread=",C.pthread_self())
   time.Sleep(time.Second)
   c_done <- true
}

#include 
#include 
#include "sync.h"



int main (){
printf("main thread=%p\n", pthread_self());
Start();
while(1) {
CWork();

    }

return 0;
}



2017-04-28 16:17 GMT+08:00 <djad...@gmail.com>:

>
>
> On Friday, April 28, 2017 at 9:18:03 AM UTC+3, hui zhang wrote:
>>
>> How let go and c code work Alternately in the same thread with
>> goroutine(corouting mechanism)
>> Check the code below.  c and go code in one thread they just do work 1 by
>> 1.
>> Expected Result
>>
>>> Do CWork
>>> Do GoWork
>>> Do CWork
>>> Do GoWork
>>> Do CWork
>>> .
>>
>>
>> //c code
>>> void CWork() {
>>> while(1) {
>>>--Print Do CWork
>>>--Coroutine Stop
>>> --switch to GoWork()
>>> }
>>> }
>>> int main() {
>>> CWork();
>>> }
>>> //go code
>>> func GoWork() {
>>> for {
>>> --Print Do GoWork
>>>--Coroutine Stop
>>> --switch back to CWork()
>>> }
>>> }
>>
>>
>>
>>
>
>
> Hi, simplest solution:
>
> //c code
>> void CWork() {
>> --Print Do CWork
>> }
>> int main() {
>> for {
>> C.CWork()
>> GoWork()
>> }
>> }
>>
>> //go code
>> func GoWork() {
>> --Print Do GoWork
>> }
>
>
>
>  Djadala
>
> --
> 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/Yaay2_UaIxU/unsubscribe.
> To unsubscribe from this group and all its topics, 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.


[go-nuts] How let go and c code work Alternately in the same thread

2017-04-28 Thread hui zhang
How let go and c code work Alternately in the same thread with 
goroutine(corouting mechanism)
Check the code below.  c and go code in one thread they just do work 1 by 1.
Expected Result 

> Do CWork
> Do GoWork
> Do CWork
> Do GoWork
> Do CWork
> .


//c code
> void CWork() {
> while(1) {
>--Print Do CWork
>--Coroutine Stop
> --switch to GoWork()
> }
> }
> int main() {
> CWork();
> }
> //go code 
> func GoWork() {
> for {
> --Print Do GoWork
>--Coroutine Stop
> --switch back to CWork()
> }
> }


 

-- 
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: void type alias can not be understood in cgo

2017-04-26 Thread hui zhang
Is this bug  in cgo  or  in clang

for  gcc runs well ?

CC=clang CGO_ENABLE=1 go build -v void.go -->fail
command-line-arguments
# command-line-arguments
./void.go:47:10: error: field has incomplete type 'GLvoid' (aka 'void')

CC=gcc CGO_ENABLE=1 go build -o void -v void.go  -->ok
command-line-arguments

在 2017年4月26日星期三 UTC+8下午4:37:38,hui zhang写道:
>
> this code runs well on ubuntu gcc --version
> gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005
> but build fail on mac
>
>  gcc --version
>
> Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr 
> --with-gxx-include-dir=/usr/include/c++/4.2.1
>
> Apple LLVM version 8.0.0 (clang-800.0.42.1)
>
> Target: x86_64-apple-darwin15.5.0
>
> Thread model: posix
>
> any workaround ?
>
>
> 在 2017年4月26日星期三 UTC+8下午3:59:15,hui zhang写道:
>>
>> I simply the case  as below , how to fix it?
>>
>> package main
>>
>> /*
>> #include 
>> #include 
>> typedef void GLvoid;
>> GLvoid Foo() {
>>printf("foo");
>> }
>> */
>> import "C"
>>
>> func main() {
>>C.Foo()
>> }
>>
>> go build void.go
>>
>> cgo-gcc-prolog:34:10: error: field has incomplete type 'GLvoid' (aka 
>> 'void')
>> 在 2017年4月26日星期三 UTC+8下午3:20:14,hui zhang写道:
>>>
>>> Check code below
>>> go call c opengl/opengles code,   typedef void GLvoid
>>>
>>> func GenVertexArrays(n int32, arrays *uint32) {
>>>//C.glGenVertexArrays((C.GLsizei)(n), 
>>> (*C.GLuint)(unsafe.Pointer(arrays)))  --> ok on darwin amd64
>>>C.glGenVertexArraysOES((C.GLsizei)(n), 
>>> (*C.GLuint)(unsafe.Pointer(arrays))) --> fail on darwin arm
>>> }
>>>
>>> Error Message
>>>
>>> cgo-gcc-prolog:36:10: error: field has incomplete type 'GLvoid' (aka 
>>> 'void')
>>> For the GLvoid(aka void)  can not be understood by cgo
>>>
>>> function decalred
>>> void *glGenVertexArrays*(GLsizei n, GLuint *arrays); -->on darwin amd64 
>>> opengl
>>>
>>> GLvoid glGenVertexArraysOES(GLsizei n, GLuint *arrays) -->on darwin arm 
>>> opengles
>>>
>>>
>>>
>>>
>>>
>>>

-- 
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: void type alias can not be understood in cgo

2017-04-26 Thread hui zhang
this code runs well on ubuntu gcc --version
gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005
but build fail on mac

 gcc --version

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr 
--with-gxx-include-dir=/usr/include/c++/4.2.1

Apple LLVM version 8.0.0 (clang-800.0.42.1)

Target: x86_64-apple-darwin15.5.0

Thread model: posix

any workaround ?


在 2017年4月26日星期三 UTC+8下午3:59:15,hui zhang写道:
>
> I simply the case  as below , how to fix it?
>
> package main
>
> /*
> #include 
> #include 
> typedef void GLvoid;
> GLvoid Foo() {
>printf("foo");
> }
> */
> import "C"
>
> func main() {
>C.Foo()
> }
>
> go build void.go
>
> cgo-gcc-prolog:34:10: error: field has incomplete type 'GLvoid' (aka 
> 'void')
> 在 2017年4月26日星期三 UTC+8下午3:20:14,hui zhang写道:
>>
>> Check code below
>> go call c opengl/opengles code,   typedef void GLvoid
>>
>> func GenVertexArrays(n int32, arrays *uint32) {
>>//C.glGenVertexArrays((C.GLsizei)(n), 
>> (*C.GLuint)(unsafe.Pointer(arrays)))  --> ok on darwin amd64
>>C.glGenVertexArraysOES((C.GLsizei)(n), 
>> (*C.GLuint)(unsafe.Pointer(arrays))) --> fail on darwin arm
>> }
>>
>> Error Message
>>
>> cgo-gcc-prolog:36:10: error: field has incomplete type 'GLvoid' (aka 
>> 'void')
>> For the GLvoid(aka void)  can not be understood by cgo
>>
>> function decalred
>> void *glGenVertexArrays*(GLsizei n, GLuint *arrays); -->on darwin amd64 
>> opengl
>>
>> GLvoid glGenVertexArraysOES(GLsizei n, GLuint *arrays) -->on darwin arm 
>> opengles
>>
>>
>>
>>
>>
>>

-- 
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: void type alias can not be understood in cgo

2017-04-26 Thread hui zhang
I simply the case  as below , how to fix it?

package main

/*
#include 
#include 
typedef void GLvoid;
GLvoid Foo() {
   printf("foo");
}
*/
import "C"

func main() {
   C.Foo()
}

go build void.go

cgo-gcc-prolog:34:10: error: field has incomplete type 'GLvoid' (aka 'void')
在 2017年4月26日星期三 UTC+8下午3:20:14,hui zhang写道:
>
> Check code below
> go call c opengl/opengles code,   typedef void GLvoid
>
> func GenVertexArrays(n int32, arrays *uint32) {
>//C.glGenVertexArrays((C.GLsizei)(n), (*C.GLuint)(unsafe.Pointer(arrays))) 
>  --> ok on darwin amd64
>C.glGenVertexArraysOES((C.GLsizei)(n), 
> (*C.GLuint)(unsafe.Pointer(arrays))) --> fail on darwin arm
> }
>
> Error Message
>
> cgo-gcc-prolog:36:10: error: field has incomplete type 'GLvoid' (aka 
> 'void')
> For the GLvoid(aka void)  can not be understood by cgo
>
> function decalred
> void *glGenVertexArrays*(GLsizei n, GLuint *arrays); -->on darwin amd64 
> opengl
>
> GLvoid glGenVertexArraysOES(GLsizei n, GLuint *arrays) -->on darwin arm 
> opengles
>
>
>
>
>
>

-- 
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] how to set different flags for different os in cgo

2017-04-19 Thread hui zhang
how ever if I exec

> go build -buildmode=c-archive -o libmug.a ./src

for mac lib build it build both and failed

so does for ios lib ,  it compile fail

>  CC=$PWD/clangwrap.sh CXX=$PWD/clangwrap.sh GOOS=darwin GOARCH=arm
> CGO_ENABLED=1  go build -buildmode=c-archive -o libmug.a ./src


 If I comment each #cgo sperately for defferent build ,  it works fine

2017-04-19 21:31 GMT+08:00 Ian Lance Taylor <i...@golang.org>:

> On Tue, Apr 18, 2017 at 11:00 PM, hui zhang <fastfad...@gmail.com> wrote:
> > I want to set different flags for different os in cgo,  how to do that in
> > cgo?
> >
> >
> >> //#cgo amd64 darwin CFLAGS: -Dxxx
> >> //#cgo amd64 darwin CXXFLAGS: -Dxxx
> >> //#cgo amd64 darwin LDFLAGS: -Lxxx
> >> //#cgo arm darwin CFLAGS: -Dxxx
> >> //#cgo arm darwin CXXFLAGS: -Dxxx
> >> //#cgo arm darwin LDFLAGS: -Lxxx
> >>
> >> //#include "c2go.h"
> >> import "C"
>
> Yes, that is how to do it, as documented at https://golang.org/cmd/cgo.
>
> Ian
>

-- 
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] what is the best way to to convert c++ std::string to go string in cgo programing?

2017-04-18 Thread hui zhang
assume there is a c++ function   string getpath()

 you mean I should do this ?

>  


char *CGetPath() {
> auto str=getpath; 
> char *c = malloc(str.length()), 
> strcpy(c,str.c_str()); 
> return c;
> }



  p :=C.CGetPath()  
>   gostr := C.GoString() 
>C.free(p)




在 2017年4月18日星期二 UTC+8下午6:44:59,Konstantin Khomoutov写道:
>
> On Tue, 18 Apr 2017 02:25:07 -0700 (PDT) 
> hui zhang <fastf...@gmail.com > wrote: 
>
> > c code 
> > string getstring() {...} 
> > 
> > go 
> > 
> > string gostr = (C.getstring()) 
>
> Oh, and note that std::string is a fat object. 
>
> So if getstring() really returns an instance of std::string, 
> and you need to actually extract its "raw bytes", you'd need to call 
> the c_str() method of std::string on that object before applying the 
> techniques from [1] to it. 
>
> 1. https://github.com/golang/go/wiki/cgo#go-strings-and-c-strings 
>

-- 
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] [golang/x/mobile] Can gomobile support build ios and android c static/dynamic lib.

2017-04-12 Thread hui zhang
Can gomobile support build ios and android c static/dynamic lib.

For some people do not link it to objc and java directly

It link with other C/C++ lib to form a common library , and then link to 
objc and java.

For example ,  in cocos2dx  , user use c++ to code.  But some logic they 
need go .

Can gomoblile add this support? 





-- 
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: Generate static library written in golang

2017-04-12 Thread hui zhang
I am using go1.8   arm/ darwin not work ,  for both bin and archive .how 
 to solve that

 GOOS=darwin GOARCH=arm GOARM=7  go build -buildmode=c-archive -o libmug.a
> can't load package: package .: no buildable Go source files in 
>
> GOOS=darwin GOARCH=arm  go build -v -o hello.ios main.go
> runtime/internal/sys
> runtime/internal/atomic
> runtime
> math
> command-line-arguments
> # command-line-arguments
> warning: unable to find runtime/cgo.a
> /usr/local/Cellar/go/1.8.1/libexec/pkg/tool/darwin_amd64/link: running 
> clang failed: exit status 1
> ld: warning: ignoring file 
> /var/folders/cp/561_gl9j1wzd8dgv_fn5mk7cgn/T/go-link-691505992/go.o, 
> file was built for armv7 which is not the architecture being linked 
> (x86_64): 
> /var/folders/cp/561_gl9j1wzd8dgv_fn5mk7cgn/T/go-link-691505992/go.o
> Undefined symbols for architecture x86_64:
>   "_main", referenced from:
>  implicit entry/start for main executable
> ld: symbol(s) not found for architecture x86_64
> clang: error: linker command failed with exit code 1 (use -v to see 
> invocation)


在 2015年6月3日星期三 UTC+8下午8:34:38,Sarim Khan写道:
>
> Hello,
>
> go version go1.4 darwin/amd64
>
> I'm trying to create a static library written in golang, then using that 
> static library in a c/obj/xcode project. 
>
> == gittu.go ==
>
> package gittu
>
> import "C"
>
> //export getGittu
> func getGittu() *C.char {
> s := "Hello Gittu"
> return C.CString(s)
> }
>
> ==
>
> After that i use "go install" to generate a gittu.a in 
> $GOPATH/pkg/darwin_amd64/..
>
> But when i include that gittu.a in xcode, i get this error,
>
> ignoring file /usr/local/Cellar/go/1.4/packages/pkg/darwin_amd64/
> github.com/sarim/gittu.a, file was built for archive which is not the 
> architecture being linked (x86_64)
>
> I manually tried to run cc, but still the same error. Any idea how to 
> generate x86_64 static lib?
>

-- 
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] how to setup go build arm support for use go on android and ios

2017-04-11 Thread hui zhang
As go support below system ,   what is the difference of   android/386 and
linux/386

are darwin/arm mean  ios ?

can go code compile as c library for android and ios ?

> go tool dist list
> android/386
> android/amd64
> android/arm
> android/arm64
> darwin/386
> darwin/amd64
> darwin/arm
> darwin/arm64
> dragonfly/amd64
> freebsd/386
> freebsd/amd64
> freebsd/arm
> linux/386
> linux/amd64
> linux/arm
> linux/arm64


2017-04-12 9:23 GMT+08:00 hui zhang <fastfad...@gmail.com>:

> I am intend to  build go code as c library ,  and link this library in
> other c code .   then integrate in android and ios.
> But I meet errors in the first step  build go code as c library for arm
> darwin
>
>
> 2017-04-12 0:14 GMT+08:00 hui zhang <fastfad...@gmail.com>:
>
>> I want to support go on android and ios.
>>
>> package main
>>> import "fmt"
>>> import "C"
>>> //export GoAdder
>>> func GoAdder(x, y int) int {
>>> fmt.Printf("Go says: adding %v and %v\n", x, y)
>>> return x + y
>>> }
>>> //export GetMugenVersion
>>> func GetMugVersion() string {
>>> str := "Go says: version = 1.0"
>>> return str
>>> }
>>> func main() {} // Required but ignored
>>>
>>
>>  this is what I tried on mac os
>>
>> GOOS=darwin GOARCH=arm GOARM=7 CGO_ENABLED=1  go build
>>> -buildmode=c-archive -o libmug_ios.a main.go
>>> # runtime/cgo
>>> clang: error: argument unused during compilation: '-mno-thumb'
>>> GOARM=7  GOARCH=arm   go build -buildmode=c-archive -o libmugen_ios.a
>>> can't load package: package .: no buildable Go source files in
>>> /Users/x/Documents/
>>>
>> --
>> 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/to
>> pic/golang-nuts/LDK6T_3Mc4o/unsubscribe.
>> To unsubscribe from this group and all its topics, 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] how to setup go build arm support for use go on android and ios

2017-04-11 Thread hui zhang
I am intend to  build go code as c library ,  and link this library in
other c code .   then integrate in android and ios.
But I meet errors in the first step  build go code as c library for arm
darwin


2017-04-12 0:14 GMT+08:00 hui zhang <fastfad...@gmail.com>:

> I want to support go on android and ios.
>
> package main
>> import "fmt"
>> import "C"
>> //export GoAdder
>> func GoAdder(x, y int) int {
>> fmt.Printf("Go says: adding %v and %v\n", x, y)
>> return x + y
>> }
>> //export GetMugenVersion
>> func GetMugVersion() string {
>> str := "Go says: version = 1.0"
>> return str
>> }
>> func main() {} // Required but ignored
>>
>
>  this is what I tried on mac os
>
> GOOS=darwin GOARCH=arm GOARM=7 CGO_ENABLED=1  go build
>> -buildmode=c-archive -o libmug_ios.a main.go
>> # runtime/cgo
>> clang: error: argument unused during compilation: '-mno-thumb'
>> GOARM=7  GOARCH=arm   go build -buildmode=c-archive -o libmugen_ios.a
>> can't load package: package .: no buildable Go source files in
>> /Users/x/Documents/
>>
> --
> 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/LDK6T_3Mc4o/unsubscribe.
> To unsubscribe from this group and all its topics, 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.


[go-nuts] how to setup go build arm support for use go on android and ios

2017-04-11 Thread hui zhang
I want to support go on android and ios.

package main
> import "fmt"
> import "C"
> //export GoAdder
> func GoAdder(x, y int) int {
> fmt.Printf("Go says: adding %v and %v\n", x, y)
> return x + y
> }
> //export GetMugenVersion
> func GetMugVersion() string {
> str := "Go says: version = 1.0"
> return str
> }
> func main() {} // Required but ignored
>

 this is what I tried on mac os

GOOS=darwin GOARCH=arm GOARM=7 CGO_ENABLED=1  go build -buildmode=c-archive 
> -o libmug_ios.a main.go 
> # runtime/cgo
> clang: error: argument unused during compilation: '-mno-thumb'
> GOARM=7  GOARCH=arm   go build -buildmode=c-archive -o libmugen_ios.a
> can't load package: package .: no buildable Go source files in 
> /Users/x/Documents/
>

-- 
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] Is the mem layout the same between go and c?

2017-04-11 Thread hui zhang
If I define the same  2 struct in c and go
can they be  passed directly with unsafe.Pointer
and how to export go struct from go to c ?   

/*
#include 

typedef struct {
int a;
int b;
} Foo;

void pass_struct(Foo *in) { printf("%d : %d\n", in->a, in->b); }

*/

import "C"
import (
"fmt"
"unsafe")

type Foo struct{ a, b int32 }

C.pass_struct((*C.Foo)(unsafe.Pointer()))

-- 
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] x/gomobile: does this project has ui support?

2017-03-31 Thread hui zhang
As far as I know ,  it is a wonderful work ,  just copy the concept for 
cocos2dx, 
it is quite suitable  to build a cross platform game engine.
however it is lack of a ui | particle  | animation  system.   
Much work need to be done.

UI I think is the most important for now.
But there seems no ui tool support.

I research on google , there is a common ui editor "overlap2d" seems 
suitable for this case.
however , still need some one to code to build the ui .

does any one has done something on this ui ?

-- 
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] how to debug in gomobile? & can gomobile support mac or linux sometime

2017-03-29 Thread hui zhang
As too me gomobile now are more like a game engine (for ui is gl) , like 
cocos2dx.
but unlike cocos2dx, it only support mobile, and did not offer a way to 
debug in wiki.

how to debug,   if it could not be debug in mobile.
at least let it support mac or linux so , so  we are easy to debug

-- 
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] gomobile build ios app fail

2017-03-27 Thread hui zhang

the gomobile wiki  do not mention how to solve ios signing properly ,  only 
with a link  that can not open.
https://github.com/golang/go/wiki/Mobile
Note: target=ios requires the host machine running OS X. You need to obtain 
a signing identity and download provisioning profiles 

 in 
order to continue.

there other people has the same problem ,  I guess nearly all developer 
 could face the same problem
https://github.com/golang/go/issues/17407
https://github.com/golang/go/issues/12660#issuecomment-145306339


Does anyone know how to do the signing identity ?

-- 
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 use go generate to generate generic code .

2017-03-10 Thread hui zhang
And pls don't tell me interface{} is good , can solve your problem bla bla 
bla
when interface{} meet slice 
[]int -->  []interface{} , 
all generic can not be done

在 2017年3月10日星期五 UTC+8下午4:29:20,hui zhang写道:
>
>
>
> I want to generate a min func 
>
> func Min(a,b T) T {
>if a < b {
>   return a
>} else {
>   return b
>}
> }
>
>
> pls generate below, pls use go generate to generate  int int64 int32 
> int16 uint64 uint32   float32 float64 
> Pls do not just paste documents.   There is a lot on google. but none of 
> them explain it clearly
> Just tell me how to do the below things generate by demo.
>
>
> func MinInt32(a,b int32) int32 {
>if a < b {
>   return a
>} else {
>   return b
>}
> }
>
> func Minint(a,b int) int {
>if a < b {
>   return a
>} else {
>   return b
>}
> }
>
> func Minfloat32(a,b float32) float32 {
>if a < b {
>   return a
>} else {
>   return b
>}
> }
>
>
> 
>
>
>
>
>
>
>
>

-- 
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] how to use go generate to generate generic code .

2017-03-10 Thread hui zhang


I want to generate a min func 

func Min(a,b T) T {
   if a < b {
  return a
   } else {
  return b
   }
}


pls generate below, pls use go generate to generate  int int64 int32 
int16 uint64 uint32   float32 float64 
Pls do not just paste documents.   There is a lot on google. but none of 
them explain it clearly
Just tell me how to do the below things generate by demo.


func MinInt32(a,b int32) int32 {
   if a < b {
  return a
   } else {
  return b
   }
}

func Minint(a,b int) int {
   if a < b {
  return a
   } else {
  return b
   }
}

func Minfloat32(a,b float32) float32 {
   if a < b {
  return a
   } else {
  return b
   }
}










-- 
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 there is pointer as there are slice already?

2017-02-27 Thread hui zhang
why there is pointer as there are slice already?   Can we remove pointer ?
any where there is a pointer could be replaced with slice.

func ptrfunc(p *int) {
  *p = 1
}
func slicefunc(p []int) {
  p[0] = 1
}

and we can defined a shortcut operator like ~   p[0].foo   =  p~foo

does that violate the golang principle, do one thing with one method




-- 
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] can I use go develop ios lib?

2017-02-27 Thread hui zhang
I want to use go to develop a lib for both ios and android.
It seems ok for android.   How about ios?
I know there is a project called *gomobile*. However ,after research I am 
not going to depend on that.
I just use it in original go.
Use golang to build dynamic library .so ,  and embedded it into cocos2dx 
(which use c++ as the programing language)
In cocos2dx I use c++ called the c interface exposed by go.

Can it work?  

According to my understanding ,  it works in theory.
But does anyone have done that before?


-- 
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] how to parse script expression with go and run the script

2017-02-14 Thread hui zhang
 I am developing a game engine 
I wish some event could be trigger by script. and this script expression is 
self-defined.
Like below 
trigger.ini 

trigger = "power >= 1000"
trigger = "statetype == A || statetype == B "
trigger = "foo() > 1"
-
*power* and *statetype* are a struct variable (it also can be defined as 
global) in go.
*foo* are a struct method (it also can be defined as global) 


how can I parse the expression like "power >= 1000"
and execute it in go.

I notice there is a  go/parse package ,  but I am not sure how to use it .

-- 
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 generate generic code with generate?

2017-01-23 Thread hui zhang
As this github auther says:
I found gengen <https://github.com/joeshaw/gengen> after implementing most 
of this functionality. It follows a similar approach, though doesn't take 
it quite as far.

gengen seems better according to github star.
I wonder if there are any better packages out there ,  have u reach on this?


在 2017年1月23日星期一 UTC+8下午10:04:22,Caleb Doxsey写道:
>
> Hi,
>
> With github.com/badgerodon/goreify you can do this:
>
> //go:generate goreify examples/min.Min numeric
>
> // Min finds the minimum value in a slice
> func Min(args ...generics.T1) (r generics.T1) {
> if len(args) == 0 {
> panic("the minimum of nothing is undefined")
> }
>
> r = args[0]
> for i := 1; i < len(args); i++ {
> if generics.Less(r, args[i]) {
> r = args[i]
> }
> }
> return r
> }
>
>
> (replacing examples/min with your package name)
>
> This gives:
>
> // MinInt finds the minimum value in a slice
> func MinInt(args ...int) (r int) {
> if len(args) == 0 {
> panic("the minimum of nothing is undefined")
> }
>
> r = args[0]
> for i := 1; i < len(args); i++ {
> if r < args[i] {
> r = args[i]
> }
> }
> return r
> }
>
>
> There are other libraries out there that can do the same thing.
>
> On Monday, January 23, 2017 at 1:19:25 AM UTC-5, hui zhang wrote:
>>
>> Since go did not support generic yet ,
>> Generate give us a alternative choice .
>> However,  although I read the official document.  
>> I still don't know how to use go generate to generate code.
>> Could anyone show us an example ?
>>
>> Let's take   std::min in c++ us an example.
>> min(x,y)   // type could be int int32 int64 int8  uint   float??
>> min(x,y,z,a,b..)  //Variable-length Argument 
>>
>

-- 
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] How to generate generic code with generate?

2017-01-22 Thread hui zhang
Since go did not support generic yet ,
Generate give us a alternative choice .
However,  although I read the official document.  
I still don't know how to use go generate to generate code.
Could anyone show us an example ?

Let's take   std::min in c++ us an example.
min(x,y)   // type could be int int32 int64 int8  uint   float??
min(x,y,z,a,b..)  //Variable-length Argument 

-- 
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] How to seek in file use bufio.Reader?

2017-01-18 Thread hui zhang
I am using  bufio.Reader  and binary.Read 
to read binary from file,  I want to seek in the file or bufio.Reader
Below code does not work 

fi.Seek(0, os.SEEK_SET) Does not work for bufio.Reader


below definition shows that r control the position , but I did not see any 
method to set it

type Reader struct {
   buf  []byte
   rd   io.Reader // reader provided by the client
   r, w int   // buf read and write positions
   err  error
   lastByte int
   lastRuneSize int
}

I expect below code to output 3.13 twice ,   but it output 3.13   3.14

package main

import (
   _ "bytes"
   "fmt"
   _ "math"

   "bufio"
   "encoding/binary"
   "os"
)

func main() {
   var pi float64
   //b := []byte{0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40,
   // 0x78, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40}
   //buf := bytes.NewReader(b)
   //err := binary.Read(buf, binary.LittleEndian, )
   //if err != nil {
   // fmt.Println("binary.Read failed:", err)
   //}
   //fmt.Println(pi)
    Output: 3.141592653589793
   //err = binary.Read(buf, binary.LittleEndian, )
   //if err != nil {
   // fmt.Println("binary.Read failed:", err)
   //}
   //fmt.Println(pi)
   //
   // open output file
   fo, err := os.Create("./output.bin")
   if err != nil {
  panic(err)
   }

   // make a write buffer
   var fl1 float64 = 3.13
   var fl2 float64 = 3.14
   w := bufio.NewWriter(fo)
   err = binary.Write(w, binary.LittleEndian, fl1)
   if err != nil {
  fmt.Println("binary.Write failed:", err)
   }
   err = binary.Write(w, binary.LittleEndian, fl2)
   if err != nil {
  fmt.Println("binary.Write failed:", err)
   }
   w.Flush()
   // close fo on exit and check for its returned error
   if err := fo.Close(); err != nil {
  panic(err)
   }

   //
   fi, err := os.Open("./output.bin")
   if err != nil {
  panic(err)
   }
   // close fi on exit and check for its returned error
   defer func() {
  if err := fi.Close(); err != nil {
 panic(err)
  }
   }()

   rd := bufio.NewReader(fi)
   err = binary.Read(rd, binary.LittleEndian, )
   if err != nil {
  fmt.Println("binary.Read failed:", err)
   }
   fmt.Println(pi)

   fi.Seek(0, os.SEEK_SET) Does not work for bufio.Reader

   err = binary.Read(rd, binary.LittleEndian, )
   if err != nil {
  fmt.Println("binary.Read failed:", err)
   }
   fmt.Println(pi)

}

-- 
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] how to seek in file using go

2017-01-18 Thread hui zhang
so the file seek does not work in bufio.Read  ?

在 2017年1月19日星期四 UTC+8下午2:59:39,hui zhang写道:
>
> fi.Seek(0, os.SEEK_SET )?
>
>
> I set this in the code  and I expected to print 3.13 twice , but this code 
> print 3.13 3.14
> why?
>
> package main
>
> import (
>_ "bytes"
>"fmt"
>_ "math"
>
>"bufio"
>"encoding/binary"
>"os"
> )
>
> func main() {
>var pi float64
>//b := []byte{0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40,
>// 0x78, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40}
>//buf := bytes.NewReader(b)
>//err := binary.Read(buf, binary.LittleEndian, )
>//if err != nil {
>// fmt.Println("binary.Read failed:", err)
>//}
>//fmt.Println(pi)
> Output: 3.141592653589793
>//err = binary.Read(buf, binary.LittleEndian, )
>//if err != nil {
>// fmt.Println("binary.Read failed:", err)
>//}
>//fmt.Println(pi)
> //
>// open output file
>fo, err := os.Create("./output.bin")
>if err != nil {
>   panic(err)
>}
>
>// make a write buffer
>var fl1 float64 = 3.13
>var fl2 float64 = 3.14
>w := bufio.NewWriter(fo)
>err = binary.Write(w, binary.LittleEndian, fl1)
>if err != nil {
>   fmt.Println("binary.Write failed:", err)
>}
>err = binary.Write(w, binary.LittleEndian, fl2)
>if err != nil {
>   fmt.Println("binary.Write failed:", err)
>}
>w.Flush()
>// close fo on exit and check for its returned error
>if err := fo.Close(); err != nil {
>   panic(err)
>}
>
>//
>fi, err := os.Open("./output.bin")
>if err != nil {
>   panic(err)
>}
>// close fi on exit and check for its returned error
>defer func() {
>   if err := fi.Close(); err != nil {
>  panic(err)
>   }
>}()
>
>rd := bufio.NewReader(fi)
>err = binary.Read(rd, binary.LittleEndian, )
>if err != nil {
>   fmt.Println("binary.Read failed:", err)
>}
>fmt.Println(pi)
>
>fi.Seek(0, os.SEEK_SET )?
>
>err = binary.Read(rd, binary.LittleEndian, )
>if err != nil {
>   fmt.Println("binary.Read failed:", err)
>}
>fmt.Println(pi)
>
> }
>
>
> 在 2017年1月19日星期四 UTC+8下午2:43:31,Ayan George写道:
>>
>>
>>
>> On 01/19/2017 01:22 AM, hui zhang wrote: 
>> > I am using encoding/binary to read/write (struct)data to/from file. 
>> > Some times , I need to seek in the file while reading . 
>> > how to do this in go. 
>> > Check the code below 
>>
>> [snip!] 
>> > 
>> > 
>> > fi, err := os.Open("./output.bin") 
>> >if err != nil { 
>> >   panic(err) 
>> >} 
>> >// close fi on exit and check for its returned error 
>> > defer func() { 
>> >   if err := fi.Close(); err != nil { 
>> >  panic(err) 
>> >   } 
>> >}() 
>> > 
>> >rd := bufio.NewReader(fi) 
>> >err = binary.Read(rd, binary.LittleEndian, ) 
>> >if err != nil { 
>> >   fmt.Println("binary.Read failed:", err) 
>> >} 
>> >fmt.Println(pi) 
>> > 
>> >fi.seek()? 
>> > 
>>
>> Is File.Seek() what you're looking for or do you need something else? 
>>
>>   https://golang.org/pkg/os/#File.Seek 
>>
>> -ayan 
>>
>>

-- 
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] how to seek in file using go

2017-01-18 Thread hui zhang


fi.Seek(0, os.SEEK_SET )?


I set this in the code  and I expected to print 3.13 twice , but this code 
print 3.13 3.14
why?

package main

import (
   _ "bytes"
   "fmt"
   _ "math"

   "bufio"
   "encoding/binary"
   "os"
)

func main() {
   var pi float64
   //b := []byte{0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40,
   // 0x78, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40}
   //buf := bytes.NewReader(b)
   //err := binary.Read(buf, binary.LittleEndian, )
   //if err != nil {
   // fmt.Println("binary.Read failed:", err)
   //}
   //fmt.Println(pi)
    Output: 3.141592653589793
   //err = binary.Read(buf, binary.LittleEndian, )
   //if err != nil {
   // fmt.Println("binary.Read failed:", err)
   //}
   //fmt.Println(pi)
//
   // open output file
   fo, err := os.Create("./output.bin")
   if err != nil {
  panic(err)
   }

   // make a write buffer
   var fl1 float64 = 3.13
   var fl2 float64 = 3.14
   w := bufio.NewWriter(fo)
   err = binary.Write(w, binary.LittleEndian, fl1)
   if err != nil {
  fmt.Println("binary.Write failed:", err)
   }
   err = binary.Write(w, binary.LittleEndian, fl2)
   if err != nil {
  fmt.Println("binary.Write failed:", err)
   }
   w.Flush()
   // close fo on exit and check for its returned error
   if err := fo.Close(); err != nil {
  panic(err)
   }

   //
   fi, err := os.Open("./output.bin")
   if err != nil {
  panic(err)
   }
   // close fi on exit and check for its returned error
   defer func() {
  if err := fi.Close(); err != nil {
 panic(err)
  }
   }()

   rd := bufio.NewReader(fi)
   err = binary.Read(rd, binary.LittleEndian, )
   if err != nil {
  fmt.Println("binary.Read failed:", err)
   }
   fmt.Println(pi)

   fi.Seek(0, os.SEEK_SET )?

   err = binary.Read(rd, binary.LittleEndian, )
   if err != nil {
  fmt.Println("binary.Read failed:", err)
   }
   fmt.Println(pi)

}


在 2017年1月19日星期四 UTC+8下午2:43:31,Ayan George写道:
>
>
>
> On 01/19/2017 01:22 AM, hui zhang wrote: 
> > I am using encoding/binary to read/write (struct)data to/from file. 
> > Some times , I need to seek in the file while reading . 
> > how to do this in go. 
> > Check the code below 
>
> [snip!] 
> > 
> > 
> > fi, err := os.Open("./output.bin") 
> >if err != nil { 
> >   panic(err) 
> >} 
> >// close fi on exit and check for its returned error 
> > defer func() { 
> >   if err := fi.Close(); err != nil { 
> >  panic(err) 
> >   } 
> >}() 
> > 
> >rd := bufio.NewReader(fi) 
> >err = binary.Read(rd, binary.LittleEndian, ) 
> >if err != nil { 
> >   fmt.Println("binary.Read failed:", err) 
> >} 
> >fmt.Println(pi) 
> > 
> >fi.seek()? 
> > 
>
> Is File.Seek() what you're looking for or do you need something else? 
>
>   https://golang.org/pkg/os/#File.Seek 
>
> -ayan 
>
>

-- 
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] how to seek in file using go

2017-01-18 Thread hui zhang
thanks all,   I use ide go to definition,  it go to the file_unix.go
in this file seek  is a private method.
So  I am confused 

在 2017年1月19日星期四 UTC+8下午2:45:16,Konstantin Khomoutov写道:
>
> On Wed, 18 Jan 2017 22:22:48 -0800 (PST) 
> hui zhang <fastf...@gmail.com > wrote: 
>
> [...] 
> >fi, err := os.Open("./output.bin") 
> [...] 
> >fi.seek()? 
>
> The usual drill is: 
>
> 1. Get the documentation on os.Open(): 
>
>  $ go doc os.Open 
>
>Notice what it returns in its 1st return value has the 
>type *File.  Since it has no "pkg." qualifier it means 
>that name is defined in the same package. 
>
> 2. So we now read the docs on os.File: 
>
>  $ go doc os.File 
>
>...and see all of its methods there, inclusing Seek(). 
>
> 3. So we read the docs on it: 
>
>  $ go doc os.File.Seek 
>

-- 
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] how to seek in file using go

2017-01-18 Thread hui zhang
I am using encoding/binary to read/write (struct)data to/from file.
Some times , I need to seek in the file while reading .
how to do this in go. 
Check the code below



package main

import (
   _ "bytes"
   "fmt"
   _ "math"

   "bufio"
   "encoding/binary"
   "os"
)

func main() {
   var pi float64
   //b := []byte{0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40,
   // 0x78, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40}
   //buf := bytes.NewReader(b)
   //err := binary.Read(buf, binary.LittleEndian, )
   //if err != nil {
   // fmt.Println("binary.Read failed:", err)
   //}
   //fmt.Println(pi)
    Output: 3.141592653589793
   //err = binary.Read(buf, binary.LittleEndian, )
   //if err != nil {
   // fmt.Println("binary.Read failed:", err)
   //}
   //fmt.Println(pi)
//
   // open output file
   fo, err := os.Create("./output.bin")
   if err != nil {
  panic(err)
   }

   // make a write buffer
   var fl1 float64 = 3.13
   var fl2 float64 = 3.14
   w := bufio.NewWriter(fo)
   err = binary.Write(w, binary.LittleEndian, fl1)
   if err != nil {
  fmt.Println("binary.Write failed:", err)
   }
   err = binary.Write(w, binary.LittleEndian, fl2)
   if err != nil {
  fmt.Println("binary.Write failed:", err)
   }
   w.Flush()
   // close fo on exit and check for its returned error
   if err := fo.Close(); err != nil {
  panic(err)
   }

   //
   fi, err := os.Open("./output.bin")
   if err != nil {
  panic(err)
   }
   // close fi on exit and check for its returned error
   defer func() {
  if err := fi.Close(); err != nil {
 panic(err)
  }
   }()

   rd := bufio.NewReader(fi)
   err = binary.Read(rd, binary.LittleEndian, )
   if err != nil {
  fmt.Println("binary.Read failed:", err)
   }
   fmt.Println(pi)

   fi.seek()?

   err = binary.Read(rd, binary.LittleEndian, )
   if err != nil {
  fmt.Println("binary.Read failed:", err)
   }
   fmt.Println(pi)

}

-- 
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] Disadvantage of Go

2017-01-13 Thread hui zhang
Yes ,   cycle import is a bad design.
But as the software becomes larger , not everything is controllable.
In real project , some times it is a great risk to do refactor.

在 2017年1月13日星期五 UTC+8下午5:56:48,rog写道:
>
> On 13 January 2017 at 07:44, hui zhang <fastf...@gmail.com > 
> wrote: 
> > 4 Can not Cycle import. 
>
> In my opinion, this is one of Go's really great features. When software 
> becomes 
> larger, there is huge pressure to create cyclic dependencies between 
> packages. 
> Once you start to get cyclic dependencies, the system as a whole tends 
> inevitably 
> to gather into a giant "ball of mud". That makes everything less 
> modular and much 
> harder to refactor. 
>
> There are so many times that I would have created a cyclic dependency 
> rather 
> than spending a day or two teasing out the dependencies into something 
> non-cyclic. 
> This process almost always creates something better engineered than before 
> with a better separation of concerns. 
>
> Also, as Egon says, there's a good technical reason: the Go 
> initialisation order depends 
> fundamentally on non-cyclic imports - there's no way to see an 
> imported package's initialised 
> global variables in an uninitialised state. 
>

-- 
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: Disadvantage of Go

2017-01-13 Thread hui zhang
I just list A B C D E F  as  an example.
In real project we will use struct in struct .
when the struct goes deeper, and it may be managed by other people,
 if the deepest struct need a default value. F{x:1} 
The upper struct user "must" known the detail. 
here below I just figure out a way below to do that, but it's not a common 
way, just I know it .
 Other people who use my lib may not .  So he maybe use the zero value F{} 
 not F{x:1}
type F struct {x int32}
var FDefault = F{x:1}
type E struct {f F}
var EDefault = E{f: FDefault}
type D struct {e E}
var DDefault = D{e: EDefault}

在 2017年1月13日星期五 UTC+8下午5:49:46,Egon写道:
>
>
>
> On Friday, 13 January 2017 11:26:29 UTC+2, hui zhang wrote:
>>
>> thank u very much.  I know they all have work around.  and I also write 
>> some util my own.
>> I just wish go to make it more simpler, wish the code could be clean and 
>> short . 
>> Right now go let programer do repeat and Mechanical work
>>
>> the top 3  are bothering me most
>> [1],[2] let me do many type cast all the time.
>> [3]  let me have to do initialize default for each struct.
>> right now I am solving [3] like this.
>> type F struct {x int32}
>> var FDefault = F{x:1}
>> type E struct {f F}
>> var EDefault = E{f: FDefault}
>> type D struct {e E}
>> var DDefault = D{e: EDefault}
>>
>>
> What is the actual code that you are working on? I doubt you have structs 
> named F, E, D.
>
> It's very hard to suggest a better model for "something" without knowing 
> what that "something" is.
>
> + Egon
>  
>
>>
>>
>> 在 2017年1月13日星期五 UTC+8下午4:39:55,Egon写道:
>>>
>>> As Shawn mentioned, most of these were decided against for varying 
>>> reasons. I'll try to give as much info as I can remember.
>>>
>>> On Friday, 13 January 2017 09:44:10 UTC+2, hui zhang wrote:
>>>>
>>>> Disadvantage of Go
>>>> 1  No Generic For Now
>>>>
>>> That make user coding repeat code many times, even for basic type such 
>>>> as int float bool
>>>> It is not easy , even to make a generic min function. 
>>>>
>>> using interface will always check type casting.
>>>> and for []interface{} in generic function, u can't do cast 
>>>>
>>>
>>> You cannot cast []interface{} to []float64 because they have different 
>>> memory layouts.
>>>  
>>>
>>>>
>>>> 2   Incomplete  Type  in Basic Lib
>>>> Take math lib as an example,   math.Max math.Min are only for float64 , 
>>>> you have do stupid conversion for other type. 
>>>>
>>>
>>>> 3  No Default Value for struct.
>>>> Consider multilayer struct.   A {B {C {D {E {F} } } } 
>>>> to init A to a default value will be complicated.
>>>> And how about  A[] slice
>>>> And what if D E F are from third party lib ?  
>>>> You have to dig into 3rd party code just for its default value. 
>>>> For It may have none zero default value. 
>>>>
>>>
>>> All structs are zero initialized.
>>>
>>> If you had default-values for structs the overhead of constructing 
>>> something becomes non-obvious.
>>>  
>>>
>>>>
>>>> 4 Can not Cycle import.
>>>> package A B can not import each other at the same time. 
>>>> While other language can.
>>>> It seems not a big deal just put the the common thing in a new package
>>>> But when the package and project grow bigger, it just easy to say.
>>>> This change will affect all caller.
>>>>
>>>
>>> Structures that have cyclic dependencies have longer compile times, init 
>>> order becomes more confusing and prone for errors, and a program having 
>>> cyclic imports is harder to understand than one without it (usually).
>>>
>>> Break cycles with DI.
>>>
>>>
>>>> 5  Inconsistent type conversion 
>>>> bool type are normal type just like int and float , 
>>>> but u can't do below.  while other type can cast to others
>>>> int(bool) bool(int) 
>>>>
>>>>
>>> https://github.com/golang/go/issues/9367#issuecomment-143128337
>>>  
>>>
>>>> 6  No multi casting expression
>>>> func foo() (int16, int8)
>>>> var i,j int32 = (int32,int32)(foo())
>>>> Since go can't do this, why go provide multi return value.
>>>>
>>>
>>>

[go-nuts] How can I compare the interface in a generic function

2017-01-05 Thread hui zhang
How can I compare the interface ?
I want to implement a generic function.
the <=>=  report error in this code

func InRange(a, b, c interface{}) bool {
   if c >= a && c <= b {
  return true
   } else {
  return false
   }
}

-- 
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.