-
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
56 changed files
with
5,058 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"Response": { | ||
"Uri": "/api/v2/album/aX3TYu!images", | ||
"AlbumImage": [ | ||
{ | ||
|
||
"ArchivedMD5": "258597waaf35aed642z08c351426b5e4", | ||
"ArchivedSize": 476277, | ||
"ArchivedUri": "http://localhost:3000/photos/photo.jpg", | ||
"Caption": "", | ||
"DateTimeUploaded": "2024-01-05T20:04:39+00:00", | ||
"FileName": "somePhoto.jpg", | ||
"ImageKey": "iTsf4K3", | ||
"IsVideo": false, | ||
"Keywords": "", | ||
"Processing": false, | ||
"UploadKey": "11112222333", | ||
"Uris": { | ||
"ImageMetadata": { | ||
"Uri": "/api/v2/image/iTsf4K3-0!metadata" | ||
} | ||
} | ||
} | ||
], | ||
"Pages": { | ||
"NextPage": "" | ||
} | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"Response": { | ||
"User": { | ||
"NickName": "myUser" | ||
} | ||
} | ||
} |
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,90 @@ | ||
package main | ||
|
||
import ( | ||
_ "embed" | ||
"encoding/json" | ||
"net/http" | ||
|
||
chi "github.com/go-chi/chi/v5" | ||
"github.com/go-chi/chi/v5/middleware" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
//go:embed authuser.json | ||
var authuser []byte | ||
|
||
//go:embed user.json | ||
var user []byte | ||
|
||
//go:embed useralbums_1.json | ||
var useralbums_1 []byte | ||
|
||
//go:embed albumimages_1.json | ||
var albumimages_1 []byte | ||
|
||
//go:embed photo.jpg | ||
var photo []byte | ||
|
||
func parseJson(content []byte) any { | ||
var dest interface{} | ||
if err := json.Unmarshal(content, &dest); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
return dest | ||
} | ||
|
||
func main() { | ||
r := chi.NewRouter() | ||
r.Use(middleware.Logger) | ||
|
||
api := chi.NewRouter() | ||
|
||
api.Route("/v2", func(r chi.Router) { | ||
// User details. Get the first page of the user albums | ||
r.Get("/user/{username}", func(w http.ResponseWriter, r *http.Request) { | ||
//username := chi.URLParam(r, "username") | ||
//resp.Response.User.Uris.UserAlbums.URI = fmt.Sprintf("/api/v2/user/%s!albums", username) | ||
responseOk(w, parseJson(user)) | ||
}) | ||
|
||
r.Get("/album/{albumId}!images", func(w http.ResponseWriter, r *http.Request) { | ||
//albumId := chi.URLParam(r, "albumId") | ||
responseOk(w, parseJson(albumimages_1)) | ||
}) | ||
|
||
r.Get("/user/{username}!albums", func(w http.ResponseWriter, r *http.Request) { | ||
responseOk(w, parseJson(useralbums_1)) | ||
}) | ||
}) | ||
|
||
api.Get("/v2!authuser", func(w http.ResponseWriter, r *http.Request) { | ||
responseOk(w, parseJson(authuser)) | ||
}) | ||
|
||
r.Mount("/api", api) | ||
|
||
r.Get("/photos/{fname}.jpg", func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "image/jpg") | ||
w.Write(photo) | ||
}) | ||
|
||
r.Get("/", func(w http.ResponseWriter, r *http.Request) { | ||
log.Infof("404 URI => %s", r.RequestURI) | ||
w.WriteHeader(http.StatusNotFound) | ||
}) | ||
|
||
addr := "127.0.0.1:3000" | ||
log.Infof("Starting server on %s", addr) | ||
http.ListenAndServe(addr, r) | ||
} | ||
|
||
func responseOk(w http.ResponseWriter, resp any) { | ||
w.Header().Set("Content-Type", "application/json") | ||
h := http.StatusOK | ||
if err := json.NewEncoder(w).Encode(resp); err != nil { | ||
log.Warnf("Error: %v", err) | ||
h = http.StatusInternalServerError | ||
} | ||
w.WriteHeader(h) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,15 @@ | ||
{ | ||
"Response": { | ||
"User": { | ||
"Uris": { | ||
"UserAlbums": { | ||
"Uri": "/api/v2/user/myUser!albums", | ||
"Locator": "Album", | ||
"LocatorType": "Objects", | ||
"UriDescription": "All of user's albums", | ||
"EndpointType": "UserAlbums" | ||
} | ||
} | ||
} | ||
} | ||
} |
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,18 @@ | ||
{ | ||
"Response": { | ||
"Uri": "/api/v2/user/myUser!albums", | ||
"Album": [ | ||
{ | ||
"UrlPath": "/MyAlbum/2024/01", | ||
"Uris": { | ||
"AlbumImages": { | ||
"Uri": "/api/v2/album/aX3TYu!images" | ||
} | ||
} | ||
} | ||
], | ||
"Pages": { | ||
"NextPage": "" | ||
} | ||
} | ||
} |
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
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.