VariableAmountOfArgs
This commit is contained in:
parent
00347310c1
commit
f88a392425
6
headFirst/args/data.txt
Normal file
6
headFirst/args/data.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
6
|
||||||
3
headFirst/args/go.mod
Normal file
3
headFirst/args/go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
module main
|
||||||
|
|
||||||
|
go 1.24.5
|
||||||
BIN
headFirst/args/main
Executable file
BIN
headFirst/args/main
Executable file
Binary file not shown.
22
headFirst/args/main.go
Normal file
22
headFirst/args/main.go
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"main/sub"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func jp (mylist ...int) {
|
||||||
|
for _,i := range mylist {
|
||||||
|
fmt.Print(i," ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
args := os.Args[1]
|
||||||
|
res := sub.Kek(args)
|
||||||
|
fmt.Println(res)
|
||||||
|
|
||||||
|
jp(1,2,3,4)
|
||||||
|
}
|
||||||
|
|
||||||
20
headFirst/args/sub/sub.go
Normal file
20
headFirst/args/sub/sub.go
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
package sub
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Kek(fileName string) []int {
|
||||||
|
var seg []int
|
||||||
|
counter := 0
|
||||||
|
file,_ := os.Open(fileName)
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
mid,_ := strconv.ParseInt(scanner.Text(),0,0)
|
||||||
|
seg = append(seg,int(mid))
|
||||||
|
counter++
|
||||||
|
}
|
||||||
|
return seg
|
||||||
|
}
|
||||||
6
headFirst/fourth/data.txt
Normal file
6
headFirst/fourth/data.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
5
|
||||||
|
6
|
||||||
|
7
|
||||||
BIN
headFirst/fourth/fourth
Executable file
BIN
headFirst/fourth/fourth
Executable file
Binary file not shown.
3
headFirst/fourth/go.mod
Normal file
3
headFirst/fourth/go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
module fourth
|
||||||
|
|
||||||
|
go 1.24.5
|
||||||
12
headFirst/fourth/main.go
Normal file
12
headFirst/fourth/main.go
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"fourth/sub"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
res := sub.Kek("data.txt")
|
||||||
|
fmt.Println(res)
|
||||||
|
}
|
||||||
20
headFirst/fourth/sub/sub.go
Normal file
20
headFirst/fourth/sub/sub.go
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
package sub
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Kek(fileName string) []int {
|
||||||
|
var seg []int
|
||||||
|
counter := 0
|
||||||
|
file,_ := os.Open(fileName)
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
mid,_ := strconv.ParseInt(scanner.Text(),0,0)
|
||||||
|
seg = append(seg,int(mid))
|
||||||
|
counter++
|
||||||
|
}
|
||||||
|
return seg
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
module third
|
module third
|
||||||
|
|
||||||
go 1.24.5
|
go 1.24.5
|
||||||
|
|
||||||
|
require github.com/headfirstgo/greeting v0.0.0-20190504033635-66e7507184ee // indirect
|
||||||
|
|
|
||||||
2
headFirst/third/go.sum
Normal file
2
headFirst/third/go.sum
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
github.com/headfirstgo/greeting v0.0.0-20190504033635-66e7507184ee h1:Hb9bIxuBldEBCjyExf8LAWdR3V7ikknAHVGfAsP7pA0=
|
||||||
|
github.com/headfirstgo/greeting v0.0.0-20190504033635-66e7507184ee/go.mod h1:VREJ5Jpvj59lYxvs0Uzt8BtzUg05tqSxp+H67JHSBn8=
|
||||||
|
|
@ -1,8 +1,28 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"third/sub"
|
||||||
|
|
||||||
|
"github.com/headfirstgo/greeting"
|
||||||
|
)
|
||||||
|
|
||||||
|
func hi(input *string) string {
|
||||||
|
if strings.TrimSpace(*input) == "kek" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
*input = "func"
|
||||||
|
return fmt.Sprintf("Hi from %s",*input)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
lol := 0.4444
|
input := "lol"
|
||||||
fmt.Printf("\nthis is float %#v\n",lol)
|
fmt.Printf("Got from func: %s\n",hi(&input))
|
||||||
|
fmt.Printf("Original one: %s\n\n\n\n",input)
|
||||||
|
|
||||||
|
sub.Hello()
|
||||||
|
sub.Hi()
|
||||||
|
|
||||||
|
greeting.Hello()
|
||||||
}
|
}
|
||||||
12
headFirst/third/sub/sub.go
Normal file
12
headFirst/third/sub/sub.go
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
package sub
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func Hi() {
|
||||||
|
fmt.Println("Hi from sub pkg")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hello() just prints out another version of greeting
|
||||||
|
func Hello() {
|
||||||
|
fmt.Println("Hello from sub package!!")
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user