Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
highlander-ticketing-go-ss2023
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yannick Ege
highlander-ticketing-go-ss2023
Commits
9d76126c
Commit
9d76126c
authored
1 year ago
by
Yege1893
Browse files
Options
Downloads
Patches
Plain Diff
chanel watching for new matches
parent
16f6ce92
No related branches found
No related tags found
1 merge request
!4
Master
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/highlanderticketing/api/match.go
+31
-11
31 additions, 11 deletions
src/highlanderticketing/api/match.go
src/highlanderticketing/main.go
+13
-1
13 additions, 1 deletion
src/highlanderticketing/main.go
with
44 additions
and
12 deletions
src/highlanderticketing/api/match.go
+
31
−
11
View file @
9d76126c
...
@@ -11,8 +11,11 @@ import (
...
@@ -11,8 +11,11 @@ import (
)
)
func
GetMatchesOfApi
(
apiUrl
string
)
([]
*
model
.
Match
,
error
)
{
func
GetMatchesOfApi
(
apiUrl
string
)
([]
*
model
.
Match
,
error
)
{
data
:=
getData
(
apiUrl
)
data
,
err
:=
getData
(
apiUrl
)
matches
,
err
:=
formatJsonCreateMatch
(
data
)
if
err
!=
nil
{
return
[]
*
model
.
Match
{},
err
}
matches
,
err
:=
formatJsonToMatch
(
data
)
if
err
!=
nil
{
if
err
!=
nil
{
return
[]
*
model
.
Match
{},
err
return
[]
*
model
.
Match
{},
err
}
}
...
@@ -20,11 +23,28 @@ func GetMatchesOfApi(apiUrl string) ([]*model.Match, error) {
...
@@ -20,11 +23,28 @@ func GetMatchesOfApi(apiUrl string) ([]*model.Match, error) {
return
matches
,
nil
return
matches
,
nil
}
}
func
getData
(
apiUrl
string
)
[]
byte
{
func
GetlatestMatchesOfApi
(
url
string
,
updateChan
chan
<-
int64
)
error
{
request
,
error
:=
http
.
NewRequest
(
"GET"
,
apiUrl
,
nil
)
data
,
err
:=
getData
(
url
)
if
err
!=
nil
{
return
err
}
matches
,
err
:=
formatJsonToMatch
(
data
)
if
err
!=
nil
{
return
err
}
for
_
,
match
:=
range
matches
{
updateChan
<-
match
.
ExternalID
}
if
error
!=
nil
{
time
.
Sleep
(
5
*
time
.
Minute
)
fmt
.
Println
(
error
)
return
nil
}
func
getData
(
apiUrl
string
)
([]
byte
,
error
)
{
request
,
err
:=
http
.
NewRequest
(
"GET"
,
apiUrl
,
nil
)
if
err
!=
nil
{
return
[]
byte
{},
err
}
}
client
:=
&
http
.
Client
{}
client
:=
&
http
.
Client
{}
response
,
error
:=
client
.
Do
(
request
)
response
,
error
:=
client
.
Do
(
request
)
...
@@ -33,17 +53,17 @@ func getData(apiUrl string) []byte {
...
@@ -33,17 +53,17 @@ func getData(apiUrl string) []byte {
fmt
.
Println
(
error
)
fmt
.
Println
(
error
)
}
}
responseBody
,
err
or
:=
io
.
ReadAll
(
response
.
Body
)
responseBody
,
err
:=
io
.
ReadAll
(
response
.
Body
)
if
err
or
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
error
)
return
[]
byte
{},
err
}
}
defer
response
.
Body
.
Close
()
defer
response
.
Body
.
Close
()
return
responseBody
return
responseBody
,
nil
}
}
func
formatJson
Create
Match
(
jsonArray
[]
byte
)
([]
*
model
.
Match
,
error
)
{
func
formatJson
To
Match
(
jsonArray
[]
byte
)
([]
*
model
.
Match
,
error
)
{
var
matches
[]
*
model
.
Match
var
matches
[]
*
model
.
Match
var
results
[]
map
[
string
]
interface
{}
var
results
[]
map
[
string
]
interface
{}
...
...
This diff is collapsed.
Click to expand it.
src/highlanderticketing/main.go
+
13
−
1
View file @
9d76126c
package
main
package
main
import
(
import
(
"fmt"
"net/http"
"net/http"
"os"
"os"
...
@@ -15,12 +16,22 @@ import (
...
@@ -15,12 +16,22 @@ import (
)
)
func
main
()
{
func
main
()
{
updateChan
:=
make
(
chan
int64
)
/*service.DeleteAllUsers()
/*service.DeleteAllUsers()
var userArray []model.User
var userArray []model.User
userArray, _ = service.GetAllUsers()
userArray, _ = service.GetAllUsers()
fmt.Println(userArray)
fmt.Println(userArray)
*/
*/
service
.
DeleteAllMatches
()
go
api
.
GetlatestMatchesOfApi
(
"https://api.openligadb.de/getmatchesbyteamid/2/8/0"
,
updateChan
)
go
func
()
{
for
{
message
:=
<-
updateChan
fmt
.
Println
(
"Empfangene Nachricht:"
,
message
)
}
}()
/*service.DeleteAllMatches()
matches, errMatches := api.GetMatchesOfApi("https://api.openligadb.de/getmatchesbyteamid/16/10/0")
matches, errMatches := api.GetMatchesOfApi("https://api.openligadb.de/getmatchesbyteamid/16/10/0")
if errMatches != nil {
if errMatches != nil {
return
return
...
@@ -28,6 +39,7 @@ func main() {
...
@@ -28,6 +39,7 @@ func main() {
for _, match := range matches {
for _, match := range matches {
service.CreateMatch(match)
service.CreateMatch(match)
}
}
*/
if
err
:=
godotenv
.
Load
(
".env"
);
err
!=
nil
{
if
err
:=
godotenv
.
Load
(
".env"
);
err
!=
nil
{
log
.
Fatalf
(
"Error loading .env file"
)
log
.
Fatalf
(
"Error loading .env file"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment