This repository has been archived by the owner on Oct 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
2,936 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ovrstat | ||
package ovrstat /* import "s32x.com/ovrstat/ovrstat" */ | ||
|
||
import ( | ||
"encoding/json" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ovrstat | ||
package ovrstat /* import "s32x.com/ovrstat/ovrstat" */ | ||
|
||
import ( | ||
"sort" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package service /* import "s32x.com/ovrstat/service" */ | ||
|
||
import "github.com/labstack/echo/v4" | ||
|
||
// newErr creates and returns a new echo HTTPError with the passed status code | ||
// and optional message. Message expected to be of type string or error | ||
func newErr(code int, message ...interface{}) error { | ||
if len(message) > 0 { | ||
switch v := message[0].(type) { | ||
case error: | ||
return echo.NewHTTPError(code, v.Error()) | ||
case string: | ||
return echo.NewHTTPError(code, v) | ||
} | ||
} | ||
return echo.NewHTTPError(code, "An error has occurred") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package service /* import "s32x.com/ovrstat/service" */ | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/labstack/echo/v4" | ||
"github.com/labstack/echo/v4/middleware" | ||
) | ||
|
||
// Start starts serving the service on the passed port | ||
func Start(port string) { | ||
// Create a new echo Echo and bind all middleware | ||
e := echo.New() | ||
e.HideBanner = true | ||
|
||
// Bind middleware | ||
e.Pre(middleware.RemoveTrailingSlashWithConfig( | ||
middleware.TrailingSlashConfig{ | ||
RedirectCode: http.StatusPermanentRedirect, | ||
})) | ||
e.Use(middleware.Logger()) | ||
e.Use(middleware.Recover()) | ||
e.Pre(middleware.Secure()) | ||
e.Use(middleware.Gzip()) | ||
e.Use(middleware.CORS()) | ||
|
||
// Serve the static web content on the base echo instance | ||
e.Static("*", "./static") | ||
|
||
// Handle stats API requests | ||
e.GET("/stats/:platform/:tag", stats) | ||
e.GET("/healthcheck", func(c echo.Context) error { | ||
return c.NoContent(http.StatusOK) | ||
}) | ||
|
||
// Listen on the specified port | ||
e.Logger.Fatal(e.Start(":" + port)) | ||
} |
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package service /* import "s32x.com/ovrstat/service" */ | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/labstack/echo/v4" | ||
"github.com/pkg/errors" | ||
"s32x.com/ovrstat/ovrstat" | ||
) | ||
|
||
// stats handles retrieving and serving Overwatch stats in JSON | ||
func stats(c echo.Context) error { | ||
// Perform a full player stats lookup | ||
stats, err := ovrstat.Stats(c.Param("platform"), c.Param("tag")) | ||
if err != nil { | ||
if err == ovrstat.ErrPlayerNotFound { | ||
return newErr(http.StatusNotFound, "Player not found") | ||
} | ||
return newErr(http.StatusInternalServerError, | ||
errors.Wrap(err, "Failed to retrieve player stats")) | ||
} | ||
return c.JSON(http.StatusOK, stats) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.