Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cdn-origin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
easrng
cdn-origin
Commits
e552b8ea
Commit
e552b8ea
authored
6 years ago
by
Dean
Browse files
Options
Downloads
Patches
Plain Diff
version 0.6.0: add tombstone object support
parent
c776506b
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
lib/db/models.go
+9
-3
9 additions, 3 deletions
lib/db/models.go
lib/db/queries.go
+11
-1
11 additions, 1 deletion
lib/db/queries.go
lib/db/sql.go
+3
-1
3 additions, 1 deletion
lib/db/sql.go
main.go
+13
-0
13 additions, 0 deletions
main.go
with
37 additions
and
5 deletions
.gitignore
+
1
−
0
View file @
e552b8ea
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
lib/db/models.go
+
9
−
3
View file @
e552b8ea
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"`
}
}
This diff is collapsed.
Click to expand it.
lib/db/queries.go
+
11
−
1
View file @
e552b8ea
...
@@ -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
}
}
This diff is collapsed.
Click to expand it.
lib/db/sql.go
+
3
−
1
View file @
e552b8ea
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
main.go
+
13
−
0
View file @
e552b8ea
...
@@ -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\n
Reason: %s"
,
ctx
.
Path
(),
reason
)
recordMetrics
(
ctx
)
}
}
}
}
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