Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Golang
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Muhammad, Hammad
Golang
Commits
921f82b4
Commit
921f82b4
authored
2 years ago
by
Muhammad, Hammad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added code related to channels and go routines
parent
47736d3d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
14 deletions
+28
-14
main.go
main.go
+28
-14
No files found.
main.go
View file @
921f82b4
...
...
@@ -2,27 +2,41 @@ package main
import
(
"fmt"
"io"
"net/http"
"
os
"
"
time
"
)
type
logWriter
struct
{}
func
main
()
{
resp
,
err
:=
http
.
Get
(
"http://google.com"
)
if
err
!=
nil
{
fmt
.
Println
(
"Error:"
,
err
)
os
.
Exit
(
1
)
links
:=
[]
string
{
"http://google.com"
,
"http://facebook.com"
,
"http://stackoverflow.com"
,
"http://golang.org"
,
"http://amazon.com"
,
}
lw
:=
logWriter
{}
c
:=
make
(
chan
string
)
for
_
,
link
:=
range
links
{
go
checkLink
(
link
,
c
)
}
io
.
Copy
(
lw
,
resp
.
Body
)
for
l
:=
range
c
{
go
func
(
link
string
)
{
time
.
Sleep
(
5
*
time
.
Second
)
checkLink
(
link
,
c
)
}(
l
)
}
}
func
(
logWriter
)
Write
(
bs
[]
byte
)
(
int
,
error
)
{
fmt
.
Println
(
string
(
bs
))
fmt
.
Println
(
"Just wrote this many bytes:"
,
len
(
bs
))
return
len
(
bs
),
nil
func
checkLink
(
link
string
,
c
chan
string
)
{
_
,
err
:=
http
.
Get
(
link
)
if
err
!=
nil
{
fmt
.
Println
(
link
,
"might be down!"
)
c
<-
link
return
}
fmt
.
Println
(
link
,
"is up!"
)
c
<-
link
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment