-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: with localstack tinyurl create api
- Loading branch information
Showing
18 changed files
with
263 additions
and
166 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 |
---|---|---|
@@ -1,8 +1,39 @@ | ||
package configs | ||
|
||
const ( | ||
ApplicationPort = ":6500" | ||
OpenAPITitle = "TinyURL API" | ||
OpenAPIVersion = "1.0.0" | ||
OpenAPIServerPath = "http://localhost:6500/api/v1" | ||
// ApplicationPort is the port the application listens on. | ||
ApplicationPort = ":6500" | ||
// OpenAPITitle is the title of the OpenAPI spec. | ||
OpenAPITitle = "TinyURL API" | ||
// OpenAPIVersion is the version of the OpenAPI spec. | ||
OpenAPIVersion = "1.0.0" | ||
// OpenAPIServerPath is the base URL for the OpenAPI spec. | ||
OpenAPIDocServerPath = "http://localhost:6500/api/v1" | ||
) | ||
|
||
// OperationID: このAPI操作の一意の識別子。これは、API内で操作を参照する際に使用されます。 | ||
// Method: HTTPメソッドを指定します。この例では http.MethodGet が使われており、これはHTTPのGETリクエストを示します。 | ||
// Path: エンドポイントのURLパスを指定します。ここでは "/greeting/{name}" となっており、{name} はパスパラメータを表しています。 | ||
// Summary: 短い説明文です。APIのドキュメントに表示され、APIの目的を簡潔に説明します。 | ||
// Description: APIエンドポイントの詳細な説明です。ここでは操作の詳細や動作についての追加情報を提供します。 | ||
// Tags: このAPI操作に関連付けられたタグのリストです。これにより、APIドキュメント内で類似の操作をグループ化することができます。 | ||
|
||
|
||
// huma.Register(app, huma.Operation{ | ||
// OperationID: "health", | ||
// Method: http.MethodGet, | ||
// Path: Router.Health, | ||
// Summary: "Health Check", | ||
// Description: "Check the health of the service.", | ||
// Tags: []string{"Public"}, | ||
// }, func(_ context.Context, _ *HealthCheckParams) (*HealthCheckQuery, error) { | ||
// resp := &HealthCheckQuery{ | ||
// Body: struct{ | ||
// Message string `json:"message,omitempty" example:"Hello, world!" doc:"Greeting message"` | ||
// }{ | ||
// Message: "ok", | ||
// }, | ||
// } | ||
// fmt.Printf("Health Check: %v\n", resp.Body.Message) | ||
// return resp, nil | ||
// }) |
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,7 +1,25 @@ | ||
package domain | ||
|
||
import ( | ||
"crypto/sha1" | ||
"encoding/base64" | ||
"strings" | ||
"time" | ||
) | ||
|
||
type ShortURL struct { | ||
ID string `json:"id"` | ||
OriginalURL string `json:"original"` | ||
CreatedAt string `json:"created_at"` | ||
} | ||
|
||
func GenerateShortURL(originalURL string) *ShortURL { | ||
hasher := sha1.New() | ||
hasher.Write([]byte(originalURL)) | ||
sha := base64.URLEncoding.EncodeToString(hasher.Sum(nil)) | ||
return &ShortURL{ | ||
ID: strings.TrimRight(sha, "=")[:7], | ||
OriginalURL: originalURL, | ||
CreatedAt: time.Now().Format(time.RFC3339), | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,11 +1,30 @@ | ||
package handler | ||
|
||
import ( | ||
"net/http" | ||
"context" | ||
|
||
"github.com/labstack/echo/v4" | ||
"github.com/naohito-T/tinyurl/backend/domain" | ||
"github.com/naohito-T/tinyurl/backend/internal/infrastructures/slog" | ||
"github.com/naohito-T/tinyurl/backend/internal/rest/container" | ||
) | ||
|
||
func ShortURLHandler(c echo.Context) error { | ||
return c.String(http.StatusOK, "OK") | ||
type ShortURLHandler struct { | ||
container *container.GuestContainer | ||
} | ||
|
||
// IShortURLHandler defines the interface for short URL handler operations. | ||
type IShortURLHandler interface { | ||
CreateShortURLHandler(ctx context.Context, originalURL string) (domain.ShortURL, error) | ||
} | ||
|
||
// NewShortURLHandler creates a new handler for short URLs. | ||
func NewShortURLHandler(c *container.GuestContainer) IShortURLHandler { | ||
return &ShortURLHandler{ | ||
container: c, | ||
} | ||
} | ||
|
||
func (s *ShortURLHandler) CreateShortURLHandler(ctx context.Context, originalURL string) (domain.ShortURL, error) { | ||
slog.NewLogger().Info("CreateShortURLHandler: %v", originalURL) | ||
return s.container.URLUsecase.CreateShortURL(ctx, originalURL) | ||
} |
Oops, something went wrong.