docs: Formatting the code
This commit is contained in:
@@ -111,7 +111,7 @@ fn main() {
|
||||
blobs: [code_blob_id]
|
||||
mime_type: 'text/plain'
|
||||
metadata: {
|
||||
'language': 'vlang',
|
||||
'language': 'vlang'
|
||||
'version': '0.3.3'
|
||||
}
|
||||
)!
|
||||
@@ -152,8 +152,8 @@ fn main() {
|
||||
blobs: [image_blob_id]
|
||||
mime_type: 'image/png'
|
||||
metadata: {
|
||||
'width': '200',
|
||||
'height': '100',
|
||||
'width': '200'
|
||||
'height': '100'
|
||||
'format': 'PNG'
|
||||
}
|
||||
)!
|
||||
@@ -274,7 +274,7 @@ fn main() {
|
||||
println('\nChecking for broken symlinks:')
|
||||
for symlink in all_symlinks {
|
||||
is_broken := fs_factory.fs_symlink.is_broken(symlink.id)!
|
||||
println('- ${symlink.name}: ${if is_broken { "BROKEN" } else { "OK" }}')
|
||||
println('- ${symlink.name}: ${if is_broken { 'BROKEN' } else { 'OK' }}')
|
||||
}
|
||||
|
||||
// Demonstrate file content retrieval
|
||||
|
||||
@@ -19,7 +19,7 @@ mut o := mydb.group.new(
|
||||
user_id: 2
|
||||
role: heromodels.GroupRole.writer
|
||||
joined_at: 0 // Will be set when adding to group
|
||||
}
|
||||
},
|
||||
]
|
||||
subgroups: []
|
||||
parent_group: 0
|
||||
|
||||
@@ -60,7 +60,9 @@ mut project := mydb.project.new(
|
||||
start_date: '2023-01-01'
|
||||
end_date: '2023-12-31'
|
||||
tags: ['sample', 'demo', 'project']
|
||||
comments: [db.CommentArg{comment: 'This is a sample project'}]
|
||||
comments: [db.CommentArg{
|
||||
comment: 'This is a sample project'
|
||||
}]
|
||||
)!
|
||||
|
||||
// Save the project to the database
|
||||
|
||||
@@ -26,8 +26,12 @@ mut issue := mydb.project_issue.new(
|
||||
children: [u32(100), u32(101)]
|
||||
tags: ['bug', 'login', 'authentication']
|
||||
comments: [
|
||||
db.CommentArg{comment: 'This issue needs to be fixed urgently'},
|
||||
db.CommentArg{comment: 'I am working on this now'}
|
||||
db.CommentArg{
|
||||
comment: 'This issue needs to be fixed urgently'
|
||||
},
|
||||
db.CommentArg{
|
||||
comment: 'I am working on this now'
|
||||
},
|
||||
]
|
||||
)!
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ pub fn encode[T](obj T) ![]u8 {
|
||||
d.add_u32(u32(obj.$(field.name)))
|
||||
} $else $if field.typ is u64 {
|
||||
d.add_u64(u64(obj.$(field.name)))
|
||||
}$else $if field.typ is i64 {
|
||||
} $else $if field.typ is i64 {
|
||||
d.add_i64(i64(obj.$(field.name)))
|
||||
} $else $if field.typ is time.Time {
|
||||
d.add_time(time.new(obj.$(field.name)))
|
||||
|
||||
@@ -2,7 +2,6 @@ module db
|
||||
|
||||
import crypto.md5
|
||||
|
||||
|
||||
@[params]
|
||||
pub struct CommentArg {
|
||||
pub mut:
|
||||
|
||||
@@ -9,7 +9,7 @@ pub fn (mut self DB) tags_get(tags []string) !u32 {
|
||||
hash := md5.hexhash(tags_fixed.join(','))
|
||||
tags_found := self.redis.hget('db:tags', hash)!
|
||||
return if tags_found == '' {
|
||||
println('tags_get: new tags: ${tags_fixed.join(",")}')
|
||||
println('tags_get: new tags: ${tags_fixed.join(',')}')
|
||||
id := self.new_id()!
|
||||
self.redis.hset('db:tags', hash, id.str())!
|
||||
self.redis.hset('db:tags', id.str(), tags_fixed.join(','))!
|
||||
|
||||
@@ -16,16 +16,16 @@ pub fn new() !FsFactory {
|
||||
return FsFactory{
|
||||
fs: DBFs{
|
||||
db: &mydb
|
||||
},
|
||||
}
|
||||
fs_blob: DBFsBlob{
|
||||
db: &mydb
|
||||
},
|
||||
}
|
||||
fs_dir: DBFsDir{
|
||||
db: &mydb
|
||||
},
|
||||
}
|
||||
fs_file: DBFsFile{
|
||||
db: &mydb
|
||||
},
|
||||
}
|
||||
fs_symlink: DBFsSymlink{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ pub fn (self Fs) type_name() string {
|
||||
return 'fs'
|
||||
}
|
||||
|
||||
pub fn (self Fs) dump(mut e &encoder.Encoder) ! {
|
||||
pub fn (self Fs) dump(mut e encoder.Encoder) ! {
|
||||
e.add_string(self.name)
|
||||
e.add_u32(self.group_id)
|
||||
e.add_u32(self.root_dir_id)
|
||||
@@ -38,7 +38,7 @@ pub fn (self Fs) dump(mut e &encoder.Encoder) ! {
|
||||
e.add_u64(self.used_bytes)
|
||||
}
|
||||
|
||||
fn (mut self DBFs) load(mut o Fs, mut e &encoder.Decoder) ! {
|
||||
fn (mut self DBFs) load(mut o Fs, mut e encoder.Decoder) ! {
|
||||
o.name = e.get_string()!
|
||||
o.group_id = e.get_u32()!
|
||||
o.root_dir_id = e.get_u32()!
|
||||
|
||||
@@ -28,7 +28,7 @@ pub fn (self FsBlob) type_name() string {
|
||||
return 'fs_blob'
|
||||
}
|
||||
|
||||
pub fn (self FsBlob) dump(mut e &encoder.Encoder) ! {
|
||||
pub fn (self FsBlob) dump(mut e encoder.Encoder) ! {
|
||||
e.add_string(self.hash)
|
||||
e.add_list_u8(self.data)
|
||||
e.add_int(self.size_bytes)
|
||||
@@ -37,7 +37,7 @@ pub fn (self FsBlob) dump(mut e &encoder.Encoder) ! {
|
||||
e.add_string(self.encoding)
|
||||
}
|
||||
|
||||
fn (mut self DBFsBlob) load(mut o FsBlob, mut e &encoder.Decoder) ! {
|
||||
fn (mut self DBFsBlob) load(mut o FsBlob, mut e encoder.Decoder) ! {
|
||||
o.hash = e.get_string()!
|
||||
o.data = e.get_list_u8()!
|
||||
o.size_bytes = e.get_int()!
|
||||
|
||||
@@ -17,7 +17,7 @@ pub mut:
|
||||
parent_id u32 // Parent directory ID (0 for root)
|
||||
}
|
||||
|
||||
//we only keep the parents, not the children, as children can be found by doing a query on parent_id, we will need some smart hsets to make this fast enough and efficient
|
||||
// we only keep the parents, not the children, as children can be found by doing a query on parent_id, we will need some smart hsets to make this fast enough and efficient
|
||||
|
||||
pub struct DBFsDir {
|
||||
pub mut:
|
||||
@@ -28,13 +28,13 @@ pub fn (self FsDir) type_name() string {
|
||||
return 'fs_dir'
|
||||
}
|
||||
|
||||
pub fn (self FsDir) dump(mut e &encoder.Encoder) ! {
|
||||
pub fn (self FsDir) dump(mut e encoder.Encoder) ! {
|
||||
e.add_string(self.name)
|
||||
e.add_u32(self.fs_id)
|
||||
e.add_u32(self.parent_id)
|
||||
}
|
||||
|
||||
fn (mut self DBFsDir) load(mut o FsDir, mut e &encoder.Decoder) ! {
|
||||
fn (mut self DBFsDir) load(mut o FsDir, mut e encoder.Decoder) ! {
|
||||
o.name = e.get_string()!
|
||||
o.fs_id = e.get_u32()!
|
||||
o.parent_id = e.get_u32()!
|
||||
@@ -54,8 +54,8 @@ pub mut:
|
||||
// get new directory, not from the DB
|
||||
pub fn (mut self DBFsDir) new(args FsDirArg) !FsDir {
|
||||
mut o := FsDir{
|
||||
name: args.name,
|
||||
fs_id: args.fs_id,
|
||||
name: args.name
|
||||
fs_id: args.fs_id
|
||||
parent_id: args.parent_id
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ pub fn (self FsFile) type_name() string {
|
||||
return 'fs_file'
|
||||
}
|
||||
|
||||
pub fn (self FsFile) dump(mut e &encoder.Encoder) ! {
|
||||
pub fn (self FsFile) dump(mut e encoder.Encoder) ! {
|
||||
e.add_string(self.name)
|
||||
e.add_u32(self.fs_id)
|
||||
|
||||
@@ -61,7 +61,7 @@ pub fn (self FsFile) dump(mut e &encoder.Encoder) ! {
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut self DBFsFile) load(mut o FsFile, mut e &encoder.Decoder) ! {
|
||||
fn (mut self DBFsFile) load(mut o FsFile, mut e encoder.Decoder) ! {
|
||||
o.name = e.get_string()!
|
||||
o.fs_id = e.get_u32()!
|
||||
|
||||
@@ -136,14 +136,14 @@ pub fn (mut self DBFsFile) new(args FsFileArg) !FsFile {
|
||||
}
|
||||
|
||||
mut o := FsFile{
|
||||
name: args.name,
|
||||
fs_id: args.fs_id,
|
||||
directories: args.directories,
|
||||
blobs: args.blobs,
|
||||
size_bytes: size,
|
||||
mime_type: args.mime_type,
|
||||
checksum: args.checksum,
|
||||
accessed_at: ourtime.now().unix(),
|
||||
name: args.name
|
||||
fs_id: args.fs_id
|
||||
directories: args.directories
|
||||
blobs: args.blobs
|
||||
size_bytes: size
|
||||
mime_type: args.mime_type
|
||||
checksum: args.checksum
|
||||
accessed_at: ourtime.now().unix()
|
||||
metadata: args.metadata
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ pub fn (self FsSymlink) type_name() string {
|
||||
return 'fs_symlink'
|
||||
}
|
||||
|
||||
pub fn (self FsSymlink) dump(mut e &encoder.Encoder) ! {
|
||||
pub fn (self FsSymlink) dump(mut e encoder.Encoder) ! {
|
||||
e.add_string(self.name)
|
||||
e.add_u32(self.fs_id)
|
||||
e.add_u32(self.parent_id)
|
||||
@@ -41,7 +41,7 @@ pub fn (self FsSymlink) dump(mut e &encoder.Encoder) ! {
|
||||
e.add_u8(u8(self.target_type))
|
||||
}
|
||||
|
||||
fn (mut self DBFsSymlink) load(mut o FsSymlink, mut e &encoder.Decoder) ! {
|
||||
fn (mut self DBFsSymlink) load(mut o FsSymlink, mut e encoder.Decoder) ! {
|
||||
o.name = e.get_string()!
|
||||
o.fs_id = e.get_u32()!
|
||||
o.parent_id = e.get_u32()!
|
||||
@@ -65,10 +65,10 @@ pub mut:
|
||||
// get new symlink, not from the DB
|
||||
pub fn (mut self DBFsSymlink) new(args FsSymlinkArg) !FsSymlink {
|
||||
mut o := FsSymlink{
|
||||
name: args.name,
|
||||
fs_id: args.fs_id,
|
||||
parent_id: args.parent_id,
|
||||
target_id: args.target_id,
|
||||
name: args.name
|
||||
fs_id: args.fs_id
|
||||
parent_id: args.parent_id
|
||||
target_id: args.target_id
|
||||
target_type: args.target_type
|
||||
}
|
||||
|
||||
|
||||
@@ -24,14 +24,14 @@ pub fn (self Calendar) type_name() string {
|
||||
return 'calendar'
|
||||
}
|
||||
|
||||
pub fn (self Calendar) dump(mut e &encoder.Encoder) ! {
|
||||
pub fn (self Calendar) dump(mut e encoder.Encoder) ! {
|
||||
e.add_list_u32(self.events)
|
||||
e.add_string(self.color)
|
||||
e.add_string(self.timezone)
|
||||
e.add_bool(self.is_public)
|
||||
}
|
||||
|
||||
fn (mut self DBCalendar) load(mut o Calendar, mut e &encoder.Decoder) ! {
|
||||
fn (mut self DBCalendar) load(mut o Calendar, mut e encoder.Decoder) ! {
|
||||
o.events = e.get_list_u32()!
|
||||
o.color = e.get_string()!
|
||||
o.timezone = e.get_string()!
|
||||
@@ -89,4 +89,3 @@ pub fn (mut self DBCalendar) get(id u32) !Calendar {
|
||||
pub fn (mut self DBCalendar) list() ![]Calendar {
|
||||
return self.db.list[Calendar]()!.map(self.get(it)!)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
module heromodels
|
||||
|
||||
import freeflowuniverse.herolib.data.encoder
|
||||
@@ -80,7 +79,7 @@ pub fn (self CalendarEvent) type_name() string {
|
||||
return 'calendar_event'
|
||||
}
|
||||
|
||||
pub fn (self CalendarEvent) dump(mut e &encoder.Encoder) ! {
|
||||
pub fn (self CalendarEvent) dump(mut e encoder.Encoder) ! {
|
||||
e.add_string(self.title)
|
||||
e.add_i64(self.start_time)
|
||||
e.add_i64(self.end_time)
|
||||
@@ -108,7 +107,7 @@ pub fn (self CalendarEvent) dump(mut e &encoder.Encoder) ! {
|
||||
e.add_string(self.timezone)
|
||||
}
|
||||
|
||||
fn (mut self DBCalendarEvent) load(mut o CalendarEvent, mut e &encoder.Decoder) ! {
|
||||
fn (mut self DBCalendarEvent) load(mut o CalendarEvent, mut e encoder.Decoder) ! {
|
||||
o.title = e.get_string()!
|
||||
o.start_time = e.get_i64()!
|
||||
o.end_time = e.get_i64()!
|
||||
@@ -116,7 +115,7 @@ fn (mut self DBCalendarEvent) load(mut o CalendarEvent, mut e &encoder.Decoder)
|
||||
o.attendees = e.get_list_u32()!
|
||||
o.fs_items = e.get_list_u32()!
|
||||
o.calendar_id = e.get_u32()!
|
||||
o.status = unsafe { EventStatus(e.get_u8()!) } //TODO: is there no better way?
|
||||
o.status = unsafe { EventStatus(e.get_u8()!) } // TODO: is there no better way?
|
||||
o.is_all_day = e.get_bool()!
|
||||
o.is_recurring = e.get_bool()!
|
||||
|
||||
|
||||
@@ -30,13 +30,13 @@ pub fn (self ChatGroup) type_name() string {
|
||||
return 'chat_group'
|
||||
}
|
||||
|
||||
pub fn (self ChatGroup) dump(mut e &encoder.Encoder) ! {
|
||||
pub fn (self ChatGroup) dump(mut e encoder.Encoder) ! {
|
||||
e.add_u8(u8(self.chat_type))
|
||||
e.add_i64(self.last_activity)
|
||||
e.add_bool(self.is_archived)
|
||||
}
|
||||
|
||||
fn (mut self DBChatGroup) load(mut o ChatGroup, mut e &encoder.Decoder) ! {
|
||||
fn (mut self DBChatGroup) load(mut o ChatGroup, mut e encoder.Decoder) ! {
|
||||
o.chat_type = unsafe { ChatType(e.get_u8()!) }
|
||||
o.last_activity = e.get_i64()!
|
||||
o.is_archived = e.get_bool()!
|
||||
|
||||
@@ -67,7 +67,7 @@ pub fn (self ChatMessage) type_name() string {
|
||||
return 'chat_message'
|
||||
}
|
||||
|
||||
pub fn (self ChatMessage) dump(mut e &encoder.Encoder) ! {
|
||||
pub fn (self ChatMessage) dump(mut e encoder.Encoder) ! {
|
||||
e.add_string(self.content)
|
||||
e.add_u32(self.chat_group_id)
|
||||
e.add_u32(self.sender_id)
|
||||
@@ -94,7 +94,7 @@ pub fn (self ChatMessage) dump(mut e &encoder.Encoder) ! {
|
||||
e.add_list_u32(self.mentions)
|
||||
}
|
||||
|
||||
fn (mut self DBChatMessage) load(mut o ChatMessage, mut e &encoder.Decoder) ! {
|
||||
fn (mut self DBChatMessage) load(mut o ChatMessage, mut e encoder.Decoder) ! {
|
||||
o.content = e.get_string()!
|
||||
o.chat_group_id = e.get_u32()!
|
||||
o.sender_id = e.get_u32()!
|
||||
|
||||
@@ -26,13 +26,13 @@ pub fn (self Comment) type_name() string {
|
||||
return 'comments'
|
||||
}
|
||||
|
||||
pub fn (self Comment) dump(mut e &encoder.Encoder) ! {
|
||||
pub fn (self Comment) dump(mut e encoder.Encoder) ! {
|
||||
e.add_string(self.comment)
|
||||
e.add_u32(self.parent)
|
||||
e.add_u32(self.author)
|
||||
}
|
||||
|
||||
fn (mut self DBComments) load(mut o Comment, mut e &encoder.Decoder) ! {
|
||||
fn (mut self DBComments) load(mut o Comment, mut e encoder.Decoder) ! {
|
||||
o.comment = e.get_string()!
|
||||
o.parent = e.get_u32()!
|
||||
o.author = e.get_u32()!
|
||||
|
||||
@@ -33,7 +33,7 @@ pub fn (self Group) type_name() string {
|
||||
return 'group'
|
||||
}
|
||||
|
||||
pub fn (self Group) dump(mut e &encoder.Encoder) ! {
|
||||
pub fn (self Group) dump(mut e encoder.Encoder) ! {
|
||||
e.add_u16(u16(self.members.len))
|
||||
for member in self.members {
|
||||
e.add_u32(member.user_id)
|
||||
@@ -45,7 +45,7 @@ pub fn (self Group) dump(mut e &encoder.Encoder) ! {
|
||||
e.add_bool(self.is_public)
|
||||
}
|
||||
|
||||
fn (mut self DBGroup) load(mut o Group, mut e &encoder.Decoder) ! {
|
||||
fn (mut self DBGroup) load(mut o Group, mut e encoder.Decoder) ! {
|
||||
members_len := e.get_u16()!
|
||||
mut members := []GroupMember{}
|
||||
for _ in 0 .. members_len {
|
||||
@@ -131,5 +131,4 @@ pub fn (mut self Group) add_member(user_id u32, role GroupRole) {
|
||||
self.members << member
|
||||
}
|
||||
|
||||
|
||||
//CUSTOM FEATURES FOR GROUP
|
||||
// CUSTOM FEATURES FOR GROUP
|
||||
|
||||
@@ -20,7 +20,7 @@ pub mut:
|
||||
|
||||
pub struct Swimlane {
|
||||
pub mut:
|
||||
name string //allways to to_lower and trim_space
|
||||
name string // allways to to_lower and trim_space
|
||||
description string
|
||||
order int
|
||||
color string
|
||||
@@ -29,7 +29,7 @@ pub mut:
|
||||
|
||||
pub struct Milestone {
|
||||
pub mut:
|
||||
name string //allways to to_lower and trim_space
|
||||
name string // allways to to_lower and trim_space
|
||||
description string
|
||||
due_date i64
|
||||
completed bool
|
||||
@@ -53,7 +53,7 @@ pub fn (self Project) type_name() string {
|
||||
return 'project'
|
||||
}
|
||||
|
||||
pub fn (self Project) dump(mut e &encoder.Encoder) ! {
|
||||
pub fn (self Project) dump(mut e encoder.Encoder) ! {
|
||||
e.add_u16(u16(self.swimlanes.len))
|
||||
for swimlane in self.swimlanes {
|
||||
e.add_string(swimlane.name)
|
||||
@@ -79,7 +79,7 @@ pub fn (self Project) dump(mut e &encoder.Encoder) ! {
|
||||
e.add_i64(self.end_date)
|
||||
}
|
||||
|
||||
fn (mut self DBProject) load(mut o Project, mut e &encoder.Decoder) ! {
|
||||
fn (mut self DBProject) load(mut o Project, mut e encoder.Decoder) ! {
|
||||
swimlanes_len := e.get_u16()!
|
||||
mut swimlanes := []Swimlane{}
|
||||
for _ in 0 .. swimlanes_len {
|
||||
|
||||
@@ -62,7 +62,7 @@ pub fn (self ProjectIssue) type_name() string {
|
||||
return 'project_issue'
|
||||
}
|
||||
|
||||
pub fn (self ProjectIssue) dump(mut e &encoder.Encoder) ! {
|
||||
pub fn (self ProjectIssue) dump(mut e encoder.Encoder) ! {
|
||||
e.add_string(self.title)
|
||||
e.add_u32(self.project_id)
|
||||
e.add_u8(u8(self.issue_type))
|
||||
@@ -79,7 +79,7 @@ pub fn (self ProjectIssue) dump(mut e &encoder.Encoder) ! {
|
||||
e.add_list_u32(self.children)
|
||||
}
|
||||
|
||||
fn (mut self DBProjectIssue) load(mut o ProjectIssue, mut e &encoder.Decoder) ! {
|
||||
fn (mut self DBProjectIssue) load(mut o ProjectIssue, mut e encoder.Decoder) ! {
|
||||
o.title = e.get_string()!
|
||||
o.project_id = e.get_u32()!
|
||||
o.issue_type = unsafe { IssueType(e.get_u8()!) }
|
||||
|
||||
@@ -30,7 +30,7 @@ pub fn (self User) type_name() string {
|
||||
return 'user'
|
||||
}
|
||||
|
||||
pub fn (self User) dump(mut e &encoder.Encoder) ! {
|
||||
pub fn (self User) dump(mut e encoder.Encoder) ! {
|
||||
e.add_string(self.email)
|
||||
e.add_string(self.public_key)
|
||||
e.add_string(self.phone)
|
||||
@@ -41,7 +41,7 @@ pub fn (self User) dump(mut e &encoder.Encoder) ! {
|
||||
e.add_u8(u8(self.status))
|
||||
}
|
||||
|
||||
fn (mut self DBUser) load(mut o User, mut e &encoder.Decoder) ! {
|
||||
fn (mut self DBUser) load(mut o User, mut e encoder.Decoder) ! {
|
||||
o.email = e.get_string()!
|
||||
o.public_key = e.get_string()!
|
||||
o.phone = e.get_string()!
|
||||
|
||||
@@ -144,7 +144,5 @@ pub fn (handler Handler) handle(request Request) !Response {
|
||||
}
|
||||
|
||||
// Execute the procedure handler with the request payload
|
||||
return procedure_func(request) or {
|
||||
panic(err)
|
||||
}
|
||||
return procedure_func(request) or { panic(err) }
|
||||
}
|
||||
@@ -16,6 +16,6 @@ pub fn new_handler[T](receiver T) Handler[T] {
|
||||
pub fn (mut h Handler[T]) handle(request jsonrpc.Request) !jsonrpc.Response {
|
||||
receiver := h.receiver
|
||||
$for method in receiver.methods {
|
||||
println("method ${method}")
|
||||
println('method ${method}')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module openrpc
|
||||
|
||||
import freeflowuniverse.herolib.core.code { Attribute, Struct, StructField, Type }
|
||||
import freeflowuniverse.herolib.core.code { Attribute, Struct, StructField }
|
||||
|
||||
const example_txt = "
|
||||
Example: Get pet example.
|
||||
|
||||
@@ -48,9 +48,7 @@ pub fn (mut client UNIXClient) call(method string, params string) !string {
|
||||
}
|
||||
|
||||
// Validate response
|
||||
response.validate() or {
|
||||
return error('Invalid response: ${err}')
|
||||
}
|
||||
response.validate() or { return error('Invalid response: ${err}') }
|
||||
|
||||
// Check ID matches
|
||||
if response.id != request.id {
|
||||
@@ -87,15 +85,11 @@ fn (mut client UNIXClient) send_request(request string) !string {
|
||||
// Send request
|
||||
console.print_debug('Sending request: ${request}')
|
||||
|
||||
conn.write_string(request) or {
|
||||
return error('Failed to send request: ${err}')
|
||||
}
|
||||
conn.write_string(request) or { return error('Failed to send request: ${err}') }
|
||||
|
||||
// Read response
|
||||
mut buffer := []u8{len: 4096}
|
||||
bytes_read := conn.read(mut buffer) or {
|
||||
return error('Failed to read response: ${err}')
|
||||
}
|
||||
bytes_read := conn.read(mut buffer) or { return error('Failed to read response: ${err}') }
|
||||
|
||||
if bytes_read == 0 {
|
||||
return error('No response received from server')
|
||||
@@ -110,9 +104,7 @@ fn (mut client UNIXClient) send_request(request string) !string {
|
||||
// ping sends a simple ping to test connectivity
|
||||
pub fn (mut client UNIXClient) ping() !bool {
|
||||
// Try to discover the specification as a connectivity test
|
||||
client.discover() or {
|
||||
return error('Ping failed: ${err}')
|
||||
}
|
||||
client.discover() or { return error('Ping failed: ${err}') }
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ fn test_full_integration() {
|
||||
name: 'result'
|
||||
schema: jsonschema.Schema{}
|
||||
}
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@@ -145,9 +145,7 @@ fn test_full_integration() {
|
||||
|
||||
// Start server in a separate thread
|
||||
spawn fn [mut server] () {
|
||||
server.start() or {
|
||||
println('Server error: ${err}')
|
||||
}
|
||||
server.start() or { println('Server error: ${err}') }
|
||||
}()
|
||||
|
||||
// Give server time to start
|
||||
@@ -169,7 +167,5 @@ fn test_full_integration() {
|
||||
println('Integration test result: ${result}')
|
||||
|
||||
// Clean up
|
||||
server.close() or {
|
||||
println('Failed to close server: ${err}')
|
||||
}
|
||||
server.close() or { println('Failed to close server: ${err}') }
|
||||
}
|
||||
|
||||
@@ -13,5 +13,6 @@ fn test_decode() ! {
|
||||
content := doc_file.read()!
|
||||
object := json.decode(OpenRPC, content)!
|
||||
assert object.openrpc == '1.0.0-rc1'
|
||||
assert object.methods.map(it.name) == ['list_pets', 'create_pet', 'get_pet', 'update_pet', 'delete_pet']
|
||||
assert object.methods.map(it.name) == ['list_pets', 'create_pet', 'get_pet', 'update_pet',
|
||||
'delete_pet']
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module openrpc
|
||||
|
||||
import json
|
||||
import x.json2 { Any }
|
||||
import x.json2
|
||||
|
||||
// encode encodes an OpenRPC document struct into json string.
|
||||
// eliminates undefined variable by calling prune on the initial encoding.
|
||||
|
||||
@@ -20,7 +20,9 @@ pub fn new(params Params) !OpenRPC {
|
||||
}
|
||||
|
||||
text := if params.path != '' {
|
||||
os.read_file(params.path) or { return error('Could not read openrpc spec file at ${params.path}: ${err}') }
|
||||
os.read_file(params.path) or {
|
||||
return error('Could not read openrpc spec file at ${params.path}: ${err}')
|
||||
}
|
||||
} else {
|
||||
params.text
|
||||
}
|
||||
|
||||
@@ -3,14 +3,11 @@ module openrpc
|
||||
import os
|
||||
import json
|
||||
|
||||
|
||||
//path to openrpc.json file
|
||||
// path to openrpc.json file
|
||||
pub fn new_handler(openrpc_path string) !Handler {
|
||||
|
||||
mut openrpc_handler := openrpc.Handler {
|
||||
mut openrpc_handler := Handler{
|
||||
specification: new(path: openrpc_path)!
|
||||
}
|
||||
|
||||
return openrpc_handler
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ pub fn test_new_unix_server() ! {
|
||||
mut server := new_unix_server(handler)!
|
||||
|
||||
defer {
|
||||
server.close() or {panic(err)}
|
||||
server.close() or { panic(err) }
|
||||
}
|
||||
|
||||
spawn server.start()
|
||||
@@ -60,8 +60,8 @@ pub fn test_unix_server_handle_connection() ! {
|
||||
mut conn := unix.connect_stream(server.socket_path)!
|
||||
|
||||
defer {
|
||||
conn.close() or {panic(err)}
|
||||
server.close() or {panic(err)}
|
||||
conn.close() or { panic(err) }
|
||||
server.close() or { panic(err) }
|
||||
}
|
||||
println('Connected to server at ${server.socket_path}')
|
||||
|
||||
@@ -72,7 +72,6 @@ pub fn test_unix_server_handle_connection() ! {
|
||||
// Send the request
|
||||
conn.write_string(request_json)!
|
||||
|
||||
|
||||
// Read the response
|
||||
mut buffer := []u8{len: 4096}
|
||||
bytes_read := conn.read(mut buffer)!
|
||||
|
||||
@@ -70,7 +70,7 @@ pub fn decode_file_metadata(data []u8) !File {
|
||||
// blocksize is max 2 bytes, so max 4gb entry size
|
||||
blocksize := d.get_u16()!
|
||||
for i in 0 .. blocksize {
|
||||
chunk_ids << d.get_u32()! or { return error('Failed to get block id ${err}') }
|
||||
chunk_ids << d.get_u32() or { return error('Failed to get block id ${err}') }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user