Skip to content
Snippets Groups Projects
Commit e552b8ea authored by Dean's avatar Dean
Browse files

version 0.6.0: add tombstone object support

parent c776506b
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,7 @@ main ...@@ -19,6 +19,7 @@ main
# Package configuration file (not including sample configuration) # Package configuration file (not including sample configuration)
config.toml config.toml
config.prod.toml
# MaxMind GeoLite2 Country database files # MaxMind GeoLite2 Country database files
GeoLite2-Country.mmdb GeoLite2-Country.mmdb
......
package db package db
import (
"time"
)
// Object represents a partial object from the database. // Object represents a partial object from the database.
type Object struct { type Object struct {
ContentType *string `json:"content_type"` ContentType *string `json:"content_type"`
DestURL *string `json:"dest_url"` DestURL *string `json:"dest_url"`
ObjectType int `json:"object_type"` ObjectType int `json:"object_type"`
DeletedAt *time.Time `json:"deleted_at"`
DeleteReason *string `json:"delete_reason"`
} }
...@@ -3,6 +3,8 @@ package db ...@@ -3,6 +3,8 @@ package db
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"github.com/lib/pq"
) )
// SelectObjectByBucketKey returns an object from a bucket and a key. // SelectObjectByBucketKey returns an object from a bucket and a key.
...@@ -12,8 +14,10 @@ func SelectObjectByBucketKey(bucket, key string) (Object, error) { ...@@ -12,8 +14,10 @@ func SelectObjectByBucketKey(bucket, key string) (Object, error) {
var contentType sql.NullString var contentType sql.NullString
var destURL sql.NullString var destURL sql.NullString
var objectType int var objectType int
var deletedAt pq.NullTime
var deleteReason sql.NullString
err := DB.QueryRow(selectObjectByBucketKey, fmt.Sprintf("%s/%s", bucket, key)). err := DB.QueryRow(selectObjectByBucketKey, fmt.Sprintf("%s/%s", bucket, key)).
Scan(&contentType, &destURL, &objectType) Scan(&contentType, &destURL, &objectType, &deletedAt, &deleteReason)
if err != nil { if err != nil {
return object, err return object, err
} }
...@@ -25,6 +29,12 @@ func SelectObjectByBucketKey(bucket, key string) (Object, error) { ...@@ -25,6 +29,12 @@ func SelectObjectByBucketKey(bucket, key string) (Object, error) {
if destURL.Valid { if destURL.Valid {
object.DestURL= &destURL.String object.DestURL= &destURL.String
} }
if deletedAt.Valid {
object.DeletedAt = &deletedAt.Time
if deleteReason.Valid {
object.DeleteReason = &deleteReason.String
}
}
object.ObjectType = objectType object.ObjectType = objectType
return object, nil return object, nil
} }
...@@ -4,7 +4,9 @@ var selectObjectByBucketKey = ` ...@@ -4,7 +4,9 @@ var selectObjectByBucketKey = `
SELECT SELECT
content_type, content_type,
dest_url, dest_url,
"type" "type",
deleted_at,
delete_reason
FROM FROM
objects objects
WHERE WHERE
......
...@@ -325,5 +325,18 @@ func requestHandler(ctx *fasthttp.RequestCtx) { ...@@ -325,5 +325,18 @@ func requestHandler(ctx *fasthttp.RequestCtx) {
ctx.SetStatusCode(fasthttp.StatusOK) ctx.SetStatusCode(fasthttp.StatusOK)
} }
recordMetrics(ctx) recordMetrics(ctx)
case 2: // tombstone
ctx.SetUserValue("object_type", "tombstone")
// Send 410 gone response
ctx.SetStatusCode(fasthttp.StatusGone)
ctx.SetContentType("text/plain; charset=utf8")
reason := "no reason specified"
if object.DeleteReason != nil && *object.DeleteReason != "" {
reason = *object.DeleteReason
}
fmt.Fprintf(ctx, "410 Gone: %s\n\nReason: %s", ctx.Path(), reason)
recordMetrics(ctx)
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment