umitoit
(uday kumar)
June 11, 2019, 9:16pm
1
I am new with go language and working with my first application.
I have my few packages and from that, I am printing data.
I want to print the same data with a certain interval.
Call all the packages in single go file, so that I can make one .exe.
I have pushed my initial code here and I wrote questions for help.
Git repository link
codekid
(Ashish Shekar)
June 11, 2019, 9:53pm
2
Solution for:
Take a look at tickers - Go by Example: Tickers . This is what you’ll need to run functions in intervals.
I see you are using a single import statement so you will have to gather all of the code which is scattered in each file into a single file.
eg; main.go
package main
import (
"fmt"
// addition: from net.go
"github.com/shirou/gopsutil/net"
"github.com/shirou/gopsutil/winservices"
ps "github.com/mitchellh/go-ps"
"golang.org/x/sys/windows/svc"
)
func main() {
listServices, _ := winservices.NewService("")
fmt.Printf("All listServices: ", listServices)
processList, _ := ps.Processes()
fmt.Printf("All ps: ", processList)
for x := range processList {
var process ps.Process
process = processList[x]
fmt.Printf("%d\t%s\n",process.Pid(),process.Executable())
}
statusHandler, _ := svc.StatusHandle()
fmt.Printf("All statusHandler: ", statusHandler)
// addition: from net.go
infoIOCounter, _ := net.IOCounters(true)
fmt.Printf("All net info: ", infoIOCounter)
}
then run go build
.
NOTE: there are several different ways to structure your code but this seems to be the simplest one
Mostly start with working on moving all code into one and start implementing tickers.
umitoit
(uday kumar)
June 11, 2019, 10:09pm
3
Thanks for your reply
Here in each file I have main function and that I do not want.
How I can call all file in a single new file like main.go
codekid
(Ashish Shekar)
June 12, 2019, 5:26am
4
Change the name of the main function in all the file except the main.go
file and then call each function in your main.go func main()
directly as it is in the same package.
this needs changes in your build command. So in go build you have to paas name of all files to create a single exe. eg: go build main.go net.go ...
and so on.
system
(system)
Closed
September 10, 2019, 5:27am
5
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.