energy/cef/cef-response.go

138 lines
3.9 KiB
Go
Raw Normal View History

2022-10-04 13:21:05 +08:00
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
2022-10-04 13:21:05 +08:00
//
//----------------------------------------
2023-02-20 14:42:17 +08:00
// CEF Response
2022-10-04 13:21:05 +08:00
package cef
import (
"github.com/energye/energy/common/imports"
2022-10-04 22:34:57 +08:00
. "github.com/energye/energy/consts"
2022-10-04 13:21:05 +08:00
"github.com/energye/golcl/lcl/api"
"unsafe"
)
2023-02-20 14:42:17 +08:00
// ICefResponse 实例
2022-10-04 13:21:05 +08:00
type ICefResponse struct {
2022-12-13 23:02:40 +08:00
instance unsafe.Pointer
2022-10-04 13:21:05 +08:00
Status int32
StatusText string
MimeType string
Charset string
Error TCefErrorCode
URL string
}
2023-02-20 14:42:17 +08:00
// ICefResponse 指针实例
2022-10-04 13:21:05 +08:00
type iCefResponse struct {
Instance uintptr
Status uintptr //int32
StatusText uintptr //string
MimeType uintptr //string
Charset uintptr //string
Error uintptr //int32
URL uintptr //string
}
2023-02-20 14:42:17 +08:00
// IsReadOnly 是否只读
2022-10-04 13:21:05 +08:00
func (m *ICefResponse) IsReadOnly() bool {
2022-12-13 23:02:40 +08:00
return api.GoBool(cefResponse_IsReadOnly(uintptr(m.instance)))
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// SetURL 设置URL
func (m *ICefResponse) SetURL(url string) {
cefResponse_SetURL(uintptr(m.instance), url)
}
// SetError 设置错误码
2022-10-04 13:21:05 +08:00
func (m *ICefResponse) SetError(error TCefErrorCode) {
2022-12-13 23:02:40 +08:00
cefResponse_SetError(uintptr(m.instance), error)
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// SetStatus 设置状态码
2022-10-04 13:21:05 +08:00
func (m *ICefResponse) SetStatus(status int32) {
2022-12-13 23:02:40 +08:00
cefResponse_SetStatus(uintptr(m.instance), status)
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// SetStatusText 设置状态文本
2022-10-04 13:21:05 +08:00
func (m *ICefResponse) SetStatusText(statusText string) {
2022-12-13 23:02:40 +08:00
cefResponse_SetStatusText(uintptr(m.instance), statusText)
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// SetMimeType mime类型
2022-10-04 13:21:05 +08:00
func (m *ICefResponse) SetMimeType(mimetype string) {
2022-12-13 23:02:40 +08:00
cefResponse_SetMimeType(uintptr(m.instance), mimetype)
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// SetCharset 设置编码
2022-10-04 13:21:05 +08:00
func (m *ICefResponse) SetCharset(charset string) {
2022-12-13 23:02:40 +08:00
cefResponse_SetCharset(uintptr(m.instance), charset)
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// GetHeaderByName
2022-10-04 13:21:05 +08:00
func (m *ICefResponse) GetHeaderByName(name string) string {
2022-12-13 23:02:40 +08:00
return api.GoStr(cefResponse_GetHeaderByName(uintptr(m.instance), name))
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// SetHeaderByName
2022-10-04 13:21:05 +08:00
func (m *ICefResponse) SetHeaderByName(name, value string, overwrite bool) {
2022-12-13 23:02:40 +08:00
cefResponse_SetHeaderByName(uintptr(m.instance), name, value, overwrite)
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// GetHeaderMap
2022-10-04 13:21:05 +08:00
func (m *ICefResponse) GetHeaderMap() *ICefStringMultiMap {
headerMap := &ICefStringMultiMap{}
2022-12-13 23:02:40 +08:00
headerMap.instance = cefResponse_GetHeaderMap(uintptr(m.instance))
2022-10-04 13:21:05 +08:00
headerMap.ptr = unsafe.Pointer(headerMap.instance)
return headerMap
}
func cefResponse_IsReadOnly(instance uintptr) uintptr {
r1, _, _ := imports.Proc(internale_cefResponse_IsReadOnly).Call(instance)
2022-10-04 13:21:05 +08:00
return r1
}
2022-12-13 22:56:36 +08:00
func cefResponse_SetError(instance uintptr, error TCefErrorCode) {
imports.Proc(internale_cefResponse_SetError).Call(instance, error.ToPtr())
2022-10-04 13:21:05 +08:00
}
func cefResponse_SetStatus(instance uintptr, error int32) {
imports.Proc(internale_cefResponse_SetStatus).Call(instance, uintptr(error))
2022-10-04 13:21:05 +08:00
}
func cefResponse_SetStatusText(instance uintptr, statusText string) {
imports.Proc(internale_cefResponse_SetStatusText).Call(instance, api.PascalStr(statusText))
2022-10-04 13:21:05 +08:00
}
func cefResponse_SetMimeType(instance uintptr, mimetype string) {
imports.Proc(internale_cefResponse_SetMimeType).Call(instance, api.PascalStr(mimetype))
2022-10-04 13:21:05 +08:00
}
func cefResponse_SetCharset(instance uintptr, charset string) {
imports.Proc(internale_cefResponse_SetCharset).Call(instance, api.PascalStr(charset))
2022-10-04 13:21:05 +08:00
}
func cefResponse_GetHeaderByName(instance uintptr, name string) uintptr {
r1, _, _ := imports.Proc(internale_cefResponse_GetHeaderByName).Call(instance, api.PascalStr(name))
2022-10-04 13:21:05 +08:00
return r1
}
func cefResponse_SetHeaderByName(instance uintptr, name, value string, overwrite bool) {
imports.Proc(internale_cefResponse_SetHeaderByName).Call(instance, api.PascalStr(name), api.PascalStr(value), api.PascalBool(overwrite))
2022-10-04 13:21:05 +08:00
}
func cefResponse_SetURL(instance uintptr, url string) {
imports.Proc(internale_cefResponse_SetURL).Call(instance, api.PascalStr(url))
2022-10-04 13:21:05 +08:00
}
func cefResponse_GetHeaderMap(instance uintptr) uintptr {
r1, _, _ := imports.Proc(internale_cefResponse_GetHeaderMap).Call(instance)
2022-10-04 13:21:05 +08:00
return r1
}