Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
exchangeserve
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
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Abdulhadi Al-Sayed
exchangeserve
Commits
9f1d8fd4
Commit
9f1d8fd4
authored
4 years ago
by
Abdulhadi Al-Sayed
Browse files
Options
Downloads
Patches
Plain Diff
updated procfile
parent
8cb64192
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
api_exchange.go
+13
-27
13 additions, 27 deletions
api_exchange.go
procfile
+1
-1
1 addition, 1 deletion
procfile
with
14 additions
and
28 deletions
api_exchange.go
+
13
−
27
View file @
9f1d8fd4
...
...
@@ -6,9 +6,10 @@ import (
"github.com/go-chi/chi"
"io"
"net/http"
"strings"
)
func
re
ply
WithData
(
w
io
.
Writer
,
response
map
[
string
]
interface
{})
{
func
re
s
WithData
(
w
io
.
Writer
,
response
map
[
string
]
interface
{})
{
// handle JSON objects
err
:=
json
.
NewEncoder
(
w
)
.
Encode
(
response
)
if
err
!=
nil
{
...
...
@@ -19,32 +20,31 @@ func replyWithData(w io.Writer, response map[string]interface{}) {
// handleHistoryGet utility function, package level, to handle GET request to history route
func
HandleHistoryGet
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
println
(
"four"
)
// Set response to be of JSON type
http
.
Header
.
Add
(
w
.
Header
(),
"content-type"
,
"application/json"
)
/*
parts := strings.Split(r.URL.Path, "/")
parts
:=
strings
.
Split
(
r
.
URL
.
Path
,
"/"
)
// error handling
if len(parts) !=
8
|| parts[
5
] != "exchangehistory" {
if
len
(
parts
)
!=
6
||
parts
[
3
]
!=
"exchangehistory"
{
http
.
Error
(
w
,
"Malformed URL"
,
http
.
StatusBadRequest
)
return
}
*/
// shortened function for extracting URL parameters
p
:=
func
(
r
*
http
.
Request
,
key
string
)
string
{
return
chi
.
URLParam
(
r
,
key
)
}
// extract URL parameters
countryName
:=
chi
.
URLParam
(
r
,
"country_name"
)
beginDate
:=
chi
.
URLParam
(
r
,
"b
egin
_da
te
"
)
endDate
:=
chi
.
URLParam
(
r
,
"e
nd
_da
te
"
)
countryName
:=
p
(
r
,
"country_name"
)
beginDate
:=
p
(
r
,
"b_year"
)
+
"-"
+
p
(
r
,
"b_month"
)
+
"-"
+
p
(
r
,
"b_da
y
"
)
endDate
:=
p
(
r
,
"e_year"
)
+
"-"
+
p
(
r
,
"e_month"
)
+
"-"
+
p
(
r
,
"e_da
y
"
)
// Request currency code for country
println
(
"five"
)
currencyCode
,
err
:=
GetCurrency
(
countryName
)
println
(
"six"
)
if
err
!=
nil
{
// Error handling bad request parameter for countryName
// In case of no server response, reply with 404
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusNotFound
)
// Error could also be a 400, but we print that only internally
fmt
.
Println
(
"HTTP status: "
+
err
.
Error
())
}
/*
// Request currency history based on date period and currency code
result
,
err
:=
GetHistory
(
beginDate
,
endDate
,
currencyCode
,
""
)
// last parameter empty because not part of request
if
err
!=
nil
{
// Error handling bad history request and json decoding
...
...
@@ -53,21 +53,9 @@ func HandleHistoryGet(w http.ResponseWriter, r *http.Request) {
// Error could also be a 400 or failure in decoding, but we print that only internally
fmt
.
Println
(
"HTTP/JSON status: "
+
err
.
Error
())
}
*/
_
,
err
=
fmt
.
Fprintf
(
w
,
"%s %s / %s"
,
currencyCode
,
beginDate
,
endDate
)
if
err
!=
nil
{
// TODO must handle the error!
}
/*
// handle JSON objects
err = json.NewEncoder(w).Encode(result)
if err != nil {
fmt.Println("ERROR encoding JSON", err)
}
*/
// Send result for processing
//reply
WithData(w, result)
res
WithData
(
w
,
result
)
}
...
...
@@ -75,10 +63,8 @@ func HandleHistoryGet(w http.ResponseWriter, r *http.Request) {
func
HandlerHistory
()
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{
httpHandler
:=
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
println
(
"two"
)
switch
r
.
Method
{
case
http
.
MethodGet
:
println
(
"three"
)
HandleHistoryGet
(
w
,
r
)
case
http
.
MethodPost
:
http
.
Error
(
w
,
"Not implemented"
,
http
.
StatusNotImplemented
)
...
...
This diff is collapsed.
Click to expand it.
procfile
+
1
−
1
View file @
9f1d8fd4
web: exchangeserve
\ No newline at end of file
web: exchange
\ No newline at end of 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