Goland Cannot convert expression of type string to type []byte - goland

I am using Goland for golang code and the convert check seems working with a bug while I transfer a "string" type to a "[]byte" type.
It can be complied correctly with a expecting result, but the tip still shows in the editor. Maybe there is something wrong in my setting? Anyone can help me?
package main
import (
"crypto/sha1"
"encoding/hex"
"fmt"
)
func Sha1(data string) string {
encrypts := sha1.New()
encrypts.Write([]byte(data)) // Cannot convert expression of type string to type []byte
return hex.EncodeToString(encrypts.Sum([]byte("")))
}
func main() {
fmt.Println(Sha1("123456"))
}
Here is my Goland editor screenshot

I posted an issue on Jetbrains track, and got replied. Only to find that my GoLand inspector works well if I pasted the same code in a brand new project. So maybe there is something wrong in my "old" project, and I will post more information if I find what's wrong in my "odd" project.

Related

Retrieve firestore-item with Dart-function in FlutterFlow

I hope somebody can help me here, because I am trying to solve this already for hours now :)
I have a Firestore-collection "hochzeiten" with a timestamp-field "datum_ablauf".
The LowCode-plattform Flutterflow offers the possibility to use "Custom Functions" - and with this I want to get the value of the field "datum_ablauf" when handing over the DocumentReference to the function. So the template of the function (the part I can't really change) looks like this:
import 'dart:math' as math;
DateTime dateAblaufFromWeddingGEHTNED(DocumentReference currWedding) {
Well - I tried a lot and nothing worked, but here is my latest try:
currWedding.get().then((snapshot) {
DateTime datum = DateTime.parse(snapshot['datum_ablauf'].toDate().toString());
return datum;
});
Sadly I always get NUl, whatever I try.
Has somebody a hint for me?
Thanks!

Where is the documentation for http.Dir

I'm trying to set up a go file server and came across the function http.Dir(path string) http.FileSystem when I looked into the documentation for FileSystem.
In the source of net/http/fs.go line 705 it says:
//To use the operating system's file system implementation,
//
// use http.Dir:
//
// http.Handle("/", http.FileServer(http.Dir("/tmp")))
But I can't find any Documentation of this function. Am I missing something?
Edit:
I missed that it's a type

How to rename a document in MarkLogic?

I have simple task to do but unable to find the exact solutions for this.I have saved a file as abc.xml in MarkLogic.How can i rename the file as some example.xml using XQuery?
Code which I tried:
xquery version "1.0-ml";
xdmp:document-rename ("/aaa.xml","/final.xml");
This is showing an error.
There is no way, that I know of, to change the document URI of an existing document. The only way I can think of is to create a new document with the same content and the new URI, and delete the existing one, in the same transaction.
Where it gets tricky is to make sure to preserve the ownership, the permissions, all the properties, the property document, make sure that the old URI is not used anywhere to link to the existing document, etc.
But usually, the document URI is never really used. You should first considering whether you really need to rename the document, and why.
(Note that saying "this is showing an error" is rarely useful on SO or on mailing lists, if you do not show what the error is.)
Florent is correct, a true 'rename' is not possible, or perhaps not even meaningful. ( analogy - rename a file from one disk to another )
"Move" however is meaningful (copy then delete in a transaction).
Defining "Move" is use case dependent - i.e. what metatdata also needs to 'move' ? permissions? collections ? document properties ? inherited permissions ?
xmlsh (http://www.xmlsh.org) implements a 'rename' (http://www.xmlsh.org/MarkLogicRename) command for the marklogic extension which is really a 'move', with the implemenation borrowed from postings on markmail (http://markmail.org/)
The implementation is the following XQuery - it doesnt do everything you might want and it might do more then you want. YMMV
https://github.com/DALDEI/xmlsh/blob/master/extensions/marklogic/src/org/xmlsh/marklogic/resources/rename.xquery
( it was also written long ago - it is likely to benefit from improvement )
I have working example this works for me.
xquery version "1.0-ml";
declare function local:document-rename(
$old-uri as xs:string, $new-uri as xs:string)
as empty-sequence()
{
xdmp:document-delete($old-uri),
let $permissions := xdmp:document-get-permissions($old-uri)
let $collections := xdmp:document-get-collections($old-uri)
return xdmp:document-insert(
$new-uri, doc($old-uri),
if ($permissions) then $permissions
else xdmp:default-permissions(),
if ($collections) then $collections
else xdmp:default-collections(),
xdmp:document-get-quality($old-uri)
)
,
let $prop-ns := namespace-uri(<prop:properties/>)
let $properties :=
xdmp:document-properties($old-uri)/node()
[ namespace-uri(.) ne $prop-ns ]
return xdmp:document-set-properties($new-uri, $properties)
};
(: function call :)
local:document-rename ("/opt/backup/x.xml","y.xml");
MarkLogic has a tutorial up addressing file renaming (moving):
https://developer.marklogic.com/recipe/move-a-document/
Importantly, it uses the function xdmp:lock-for-update() to prevent modifications to the source file while it is being copied to the target location.
Also, if you are doing a batch renaming you'll want to make sure that each file URI you rename corresponds to a document in the database or you'll get runtime errors.

Can't access PFObject as dictionary

I am starting to use Parse and in the documentation it has examples to use the PFObject as an NSDitionary like this:
// Create the post
PFObject *myPost = [PFObject objectWithClassName:#"Post"];
myPost[#"title"] = #"I'm Hungry";
but i am getting a compiler error:
"Expected method to write dictionary element not found on object of type "PFObject"
But if I access the myPost PFObject like this, it works:
[myPost setObject:#"I'm Hungry" forKey:#"title"];
What is the problem?
I though that PFObject could be accesses as a dictionary?
thanks
I would check that you are using the latest version of the Parse SDK. This is new functionality and my guess is you haven't downloaded the SDK since this feature was introduced.
when i try your code at my side it gives me success message. I think you are using old parse library.
Thanks.
Downloading latest XCode should help. Subscript syntax is available from Xcode 4.4+

why does this attributed string stmt crash?

I'm trying to learn how to use attributed strings. This statement caused a "EXC_BAD_ACCESS":
NSDictionary *attDict = #{ NSForegroundColorAttributeName : [UIColor redColor] };
The way I read the documentation NSForegroundColorAttributeName is an NSString, so I then tried this but got the same crash:
NSLog(#"NSForegroundColorAttributeName: %#", NSForegroundColorAttributeName );
and also this and got the same crash:
NSString *fcan = NSForegroundColorAttributeName;
So it looks like any mention of NSForegroundColorAttributeName causes a crash. I did try other xxxAttributeNames and they do the same thing. I am importing UIKit/UIkit.h. There are no compiler warnings and no run time messages. What am I missing? Is there something else I need to import or assign? Do I have the whole concept wrong? I don't think there are any Apple code samples that cover this.
Using the newer NS* constants compiles because the extern for them is present in a header (if you build with "Latest iOS" SDK, but if you execute this code on a device that has not iOS 6 but lower then you get the crash you describe.

Resources