# README
Server
API List
Name | Route | Method | Remark |
---|---|---|---|
Navigation Page | / | GET | |
Login Page | /login/index | GET | |
User Sign In API | /signin | POST | |
Source File Server | /source/ | GET | |
DestPath File Server | /dest/ | GET | |
File Query API | /query | GET | |
File Push API | /w/push | POST | |
PProf API | /manage/pprof | GET | |
Config API | /manage/config | GET | |
Report API | /manage/report | GET |
File Query API
Support query source or dest path from File Server.
Request
Method
GET
Parameter
Request field description:
path
query file path, for examplepath=source
need_hash
return file hash or not,1
or0
, default is0
need_checkpoint
return file checkpoint hash or not,1
or0
, default is0
Example
Query the source path and return all files and checkpoints hash values.
http://127.0.0.1/query?path=source&need_hash=1&need_checkpoint=1
Response
Parameter
Response field description:
code
status code,1
means success, all status codes see Status Codemessage
response status descriptiondata
response datapath
file pathis_dir
is directory or not,1
or0
size
file size of bytes, directory is always0
hash
return file hash value if setneed_hash=1
hash_values
return the hash value of the entire file and first chunk and some checkpoints if setneed_checkpoint=1
. The details of checkpoints see the use ofcheckpoint_count
flagoffset
the file data to calculate the hash value from zero to offsethash
the file checkpoint hash value
c_time
file creation timea_time
file last access timem_time
file last modify timelink_to
link to the real file
Example
Here is an example response:
{
"code": 1,
"message": "success",
"data": [
{
"path": "go1.18.linux-amd64.tar.gz",
"is_dir": 0,
"size": 141702072,
"hash": "67622d8e307cb055b8ce2c2e03cb58cf",
"hash_values": [
{
"offset": 1048576,
"hash": "29d68359be77cdbe3d59791f0e367012"
},
{
"offset": 13631488,
"hash": "576b3746abb1f71bfbc794c750fb2c19"
},
{
"offset": 27262976,
"hash": "3a720d0a1a1c8abce3bf39cb7bc38507"
},
{
"offset": 40894464,
"hash": "946efd928cda9d0b20e9a74c4ba5db4f"
},
{
"offset": 54525952,
"hash": "eae47693bea9473c5ed859862685e4a7"
},
{
"offset": 68157440,
"hash": "ea700e864621fbee4a50d7b0e70b2e52"
},
{
"offset": 81788928,
"hash": "6c68022d11128ba256fb73a90b5232ef"
},
{
"offset": 95420416,
"hash": "ccfb4397caee4088b90e45d07829f1bf"
},
{
"offset": 109051904,
"hash": "d01e494ca88aa08d8a8a5279948db0b0"
},
{
"offset": 122683392,
"hash": "86bf50e8553674c26e2fbdb4477e44f4"
},
{
"offset": 136314880,
"hash": "51bba2e19d9519babccb0d5f4eedd7c3"
},
{
"offset": 141702072,
"hash": "67622d8e307cb055b8ce2c2e03cb58cf"
}
],
"c_time": 1649431872,
"a_time": 1649431873,
"m_time": 1647397031,
"link_to": ""
},
{
"path": "hello_gofs.txt",
"is_dir": 0,
"size": 11,
"hash": "5eb63bbbe01eeed093cb22bb8f5acdc3",
"hash_values": [
{
"offset": 11,
"hash": "5eb63bbbe01eeed093cb22bb8f5acdc3"
}
],
"c_time": 1649431542,
"a_time": 1649434237,
"m_time": 1649434237,
"link_to": ""
},
{
"path": "resource",
"is_dir": 1,
"size": 0,
"hash": "",
"hash_values": null,
"c_time": 1649431669,
"a_time": 1649431898,
"m_time": 1649431898,
"link_to": ""
}
]
}
File Push API
Push the file changes to the Remote Push Server.
Request
Method
POST
Parameter
Request field description:
push_data
the request data of push api, contains basic push file info and chunk info etcaction
the action of file change, Create(1) Write(2) Remove(3) Rename(4) Chmod(5) Symlink(6)push_action
the file upload action, CompareFile(1) CompareChunk(2) CompareFileAndChunk(3) Write(4) Truncate(5)file_info
basic push file infopath
file pathis_dir
is directory or not,1
or0
size
file size of bytes, directory is always0
hash
file hash valuec_time
file creation timea_time
file last access timem_time
file last modify timelink_to
link to the real file
chunk
offset
the offset relative to the origin of the filesize
file chunk size of bytes, directory is always0
hash
file chunk hash value
force_checksum
if the file size and file modification time of the source file is equal to the destination file and force_checksum isfalse
, then ignore the current file transfer, default isfalse
up_file
the field name of upload file or chunk
Example
Upload a file to the remote push server.
POST https://127.0.0.1/w/push HTTP/1.1
Host: 127.0.0.1
User-Agent: Go-http-client/1.1
Content-Length: 674
Content-Type: multipart/form-data; boundary=d9e3eb63103de1c2698b0675a70567e47bed1b06c71ff9e26199967312d1
Cookie: session_id=MTY1MTY4MTkxNXxOd3dBTkVkQlZFMUNTVk5UTmsxS00wNVlTbEJMTnpJM1RFWklVVmhQUTBsTlFWaEZUbFZhVjB4VU5UYzJTazFNTWpSRFJFWlpUVUU9fMFwFk6SpF9vVsNcwNe6LnmxVCgshxv-ubZzZbTTDgnq
Accept-Encoding: gzip
--d9e3eb63103de1c2698b0675a70567e47bed1b06c71ff9e26199967312d1
Content-Disposition: form-data; name="push_data"
{"action":2,"push_action":4,"file_info":{"path":"hello_gofs.txt","is_dir":0,"size":5,"hash":"5d41402abc4b2a76b9719d911017c592","hash_values":null,"c_time":1651681421,"a_time":1651681421,"m_time":1651681421,"link_to":""},"chunk":{"offset":0,"hash":"5d41402abc4b2a76b9719d911017c592","size":5},"force_checksum":false}
--d9e3eb63103de1c2698b0675a70567e47bed1b06c71ff9e26199967312d1
Content-Disposition: form-data; name="up_file"; filename="hello_gofs.txt"
Content-Type: application/octet-stream
hello
--d9e3eb63103de1c2698b0675a70567e47bed1b06c71ff9e26199967312d1--
Response
Parameter
Response field description:
code
status code,1
means success, all status codes see Status Codemessage
response status descriptiondata
response data
Example
Here is an example response:
{
"code": 1,
"message": "success",
"data": null
}
Report API
Query the report data if you enable the manage
and report
flags.
Request
Method
GET
Example
https://127.0.0.1/manage/report
Response
Parameter
Response field description:
code
status code,1
means success, all status codes see Status Codemessage
response status descriptiondata
response datacurrent_time
returns the current server timestart_time
returns the server start timeup_time
returns the server up timepid
returns the process id of the callerppid
returns the process id of the caller's parenthostname
returns the host name reported by the kernelgo_os
is the running program's operating system targetgo_arch
is the running program's architecture targetgo_version
returns the Go tree's version stringversion
returns the version info of the gofscommit
returns last commit hash value of the gofsonline
returns the client connection info that is onlineaddr
the client connection addressusername
the username of clientperm
the permission of clientconnect_time
the connected time of clientdisconnect_time
the disconnected time of clientlife_time
the lifetime of a client, it is0s
always that if the client is online
offline
returns the client connection info that is offline, full fields seeonline
events
returns some latest file change eventsname
the path of file changeop
the operation of file changetime
the time of file change
event_stat
returns the statistical data of file change eventsapi_stat
returns the statistical data of api access infoaccess_count
all the api access countvisitor_stat
the statistical data of visitors
Example
Here is an example response:
{
"code": 1,
"message": "success",
"data": {
"current_time": "2022-03-28 01:36:31",
"start_time": "2022-03-28 01:00:00",
"up_time": "36m31s",
"pid": 94032,
"ppid": 9268,
"hostname": "no-src",
"go_os": "windows",
"go_arch": "amd64",
"go_version": "go1.18",
"version": "v0.4.0",
"commit": "753f90b3dd1454ca4c87f43b1bb5e6aaabbd7689",
"online": {
"127.0.0.1:11993": {
"addr": "127.0.0.1:11993",
"username": "698d51a19d8a121c",
"perm": "rwx",
"connect_time": "2022-03-28 01:10:11",
"disconnect_time": "1970-01-01 08:00:00",
"life_time": "0s"
}
},
"offline": [
{
"addr": "127.0.0.1:11887",
"username": "698d51a19d8a121c",
"perm": "rwx",
"connect_time": "2022-03-28 01:08:46",
"disconnect_time": "2022-03-28 01:10:06",
"life_time": "1m20s"
}
],
"events": [
{
"name": "C:\\workspace\\hello_gofs.txt",
"op": "WRITE",
"time": "2022-03-28 01:10:01"
}
],
"event_stat": {
"WRITE": 1
},
"api_stat": {
"access_count": 14,
"visitor_stat": {
"127.0.0.1": 11,
"192.168.0.106": 3
}
}
}
}
Status Code
All common response status code enums below.
0
Unknown1
Success-1
Fail-2
Unauthorized-3
NotFound-4
NoPermission-5
ServerError-6
AccessDeny-7
NotModified-8
ChunkNotModified-9
Modified-10
ChunkModified
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Functions
GenerateAddr generate http or https address.
NewApiResult create an instance of the ApiResult.
NewErrorApiResult create an instance of the ApiResult that contains error info.
NewServerErrorResult create an instance of the ApiResult that means server error.
NewServerOption create an instance of the Option, store all the web server options.
NewSessionStore create a session store, stored in memory or redis.
# Constants
DefaultAddrHttp the default http address.
DefaultAddrHttps the default https address.
DefaultPortHttp the default port of http server.
DefaultPortHttps the default port of https server.
DefaultRoute the route of default.
DestRoutePrefix the route prefix of dest.
LoginGroupRoute the group route of login.
LoginIndexFullRoute the full route of login index page.
LoginIndexRoute the route of login index page.
LoginSignInFullRoute the full route of sign in api.
LoginSignInRoute the route of sign in api.
ManageConfigRoute the route of manage config api.
ManageGroupRoute the group route of manage api.
ManageReportRoute the route of report api.
ParamFormat the format of config file, support json and yaml currently.
ParamPassword the parameter name of password.
ParamReturnUrl the parameter name of return url.
ParamUserName the parameter name of username.
PProfRoutePrefix the route prefix of pprof.
PushFullRoute the full route of push api.
PushRoute the route of push api.
QueryRoute the route of query api.
ResourceTemplatePath the web server template resource path.
RootGroupRoute the group route of root.
SchemeHttp the http scheme name.
SchemeHttps the https scheme name.
SessionName the name of the session.
SessionUser the key of the session user.
SourceRoutePrefix the route prefix of source.
WriteGroupRoute the group route of write api.
# Variables
Templates the web server templates
go:embed template/*.