diff --git a/AR/.gitignore b/AR/.gitignore new file mode 100644 index 000000000..d32ab44ef --- /dev/null +++ b/AR/.gitignore @@ -0,0 +1,3 @@ +server/node_modules/* + + diff --git a/AR/a.code-workspace b/AR/a.code-workspace new file mode 100644 index 000000000..362d7c25b --- /dev/null +++ b/AR/a.code-workspace @@ -0,0 +1,7 @@ +{ + "folders": [ + { + "path": "." + } + ] +} \ No newline at end of file diff --git a/AR/form.html b/AR/form.html new file mode 100644 index 000000000..af7316bc6 --- /dev/null +++ b/AR/form.html @@ -0,0 +1,122 @@ + + + + + + + + + + +
+

誰でもAR名刺!!

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ QRコード作成 +
+
+
+
+ + + + URL + + +

{{ QRurl }}

+
+ +
+
+
+
+ + + + + + + + diff --git a/AR/form.js b/AR/form.js new file mode 100644 index 000000000..1d90318f6 --- /dev/null +++ b/AR/form.js @@ -0,0 +1,80 @@ +//display urlは名刺を表示するためのページ +const display_url = "https://seven320.github.io/AR/profile.html" +const local_url = `file:///Users/kenkato/html_css/AR/profile.html` + +//base url はQRのコードを手に入れるローカルサーバーにアクセス +const base_url = "https://00ea0ebe.ngrok.io" // use ngrok and connect local server to public server + + +var app = new Vue({ + el:'#app', + vuetify: new Vuetify(), + data: () => ({ + valid: false, + name: "name", + belong: "university", + tel: "xx-xxxx-xxxx", + email: "xxxxxxxx@google.co.jp", + twitterID: "@", + githubID: "", + description: "", + debug_QRurl: "", + QRurl:"", + get_encode_QRurl:"", + QRimagebase64:"", + nameRules:[ + v => !!v || "Name is required", + v => v.length <= 30 || "Name must be less than 30 characters", + ], + belongRules:[ + v => !!v || "belongs is required", + v => v.length <= 255 || "Name must be less than 255 characters", + ], + telRules:[ + v => !!v || "TEL is required", + v => v.length <= 20 || "TEL must be less than 20 characters" + ], + emailRules:[ + v => !!v || "e-mail is required", + v => v.length <= 255 || "e-mail must be less than 255 characters" + ] + }), + created: function(){ + this.displayConsole(); + + }, + methods:{ + displayConsole: function(){ + console.log("successs load") + }, + getForm: function(){ + if (this.name.length==0){ + alert("name is required") + } else if(this.belong.length==0){ + alert("belong is required") + } else if(this.tel.length==0){ + alert("TEL is required") + } else if(this.email.length==0){ + alert("e-mail is required") + } + this.debug_QRurl = `${local_url}?query=${this.name}---${this.belong}---${this.tel}---${this.email}---${this.twitterID}---${this.githubID}---${this.description}` + this.QRurl = `${display_url}?query=${this.name}---${this.belong}---${this.tel}---${this.email}---${this.twitterID}---${this.githubID}---${this.description}` + this.get_encode_QRurl = encodeURIComponent(`${display_url}?query=${this.name}---${this.belong}---${this.tel}---${this.email}---${this.twitterID}---${this.githubID}---${this.description}`) + }, + getQRcode: async function(){ + console.log(this.getQRurl) + let requesturl = `${base_url}/qr/${this.get_encode_QRurl}` // for public server + + + console.log("requesturl",requesturl) + let response = await fetch(requesturl, { + method:"GET", + }) + let hoge = await console.log(response) + let base64 = await response.text() + // this.QRimagebase64 = "data:image/png;base64," + base64 + this.QRimagebase64 = base64 + console.log("base64",base64) + } + } +}) \ No newline at end of file diff --git a/AR/marker/icon.png b/AR/marker/icon.png new file mode 100644 index 000000000..86b952215 Binary files /dev/null and b/AR/marker/icon.png differ diff --git a/AR/marker/pattern-treasure.patt b/AR/marker/pattern-treasure.patt new file mode 100644 index 000000000..763a279bc --- /dev/null +++ b/AR/marker/pattern-treasure.patt @@ -0,0 +1,195 @@ +128 135 161 175 183 188 190 186 177 173 187 194 195 191 185 166 +131 136 155 169 178 183 186 183 175 174 181 191 188 179 157 125 +130 136 151 164 173 177 179 178 177 178 182 190 194 188 175 112 +144 145 144 156 165 170 171 174 175 181 180 184 194 197 189 126 +144 145 143 152 161 166 169 169 171 173 173 178 192 197 197 183 +143 144 140 143 156 163 165 163 159 162 166 171 187 193 195 196 +138 152 144 127 141 150 149 138 125 122 154 164 171 188 187 192 +125 150 81 189 163 200 139 178 139 135 164 190 217 158 210 174 + 57 113 79 205 105 189 133 187 164 149 170 185 220 124 189 152 + 63 71 73 72 80 64 50 35 40 63 57 86 60 60 83 83 + 58 59 76 131 110 119 84 104 97 69 70 85 77 27 53 36 + 55 90 66 62 44 31 39 77 101 111 77 98 54 44 73 47 + 80 63 76 55 51 58 71 86 115 130 112 105 104 66 90 78 + 49 30 32 36 54 74 75 112 86 60 62 43 101 35 44 61 + 22 21 25 30 41 41 59 50 74 37 26 14 28 21 51 84 + 18 24 31 20 16 39 40 35 35 31 13 15 21 25 48 74 + 61 72 109 138 154 165 168 158 133 130 167 184 185 175 162 119 + 63 69 98 126 145 154 159 152 139 137 150 164 152 131 104 52 + 59 64 88 115 135 143 145 142 135 135 141 155 163 143 117 47 + 69 74 76 100 120 129 126 126 125 127 126 134 154 160 133 44 + 70 74 76 92 109 116 114 110 107 105 99 106 134 135 132 109 + 69 74 72 80 98 105 101 93 86 85 84 87 117 110 111 125 + 67 93 85 64 77 83 74 60 50 43 69 75 73 116 94 119 + 58 103 43 168 119 171 86 152 113 100 125 149 192 88 169 76 + 28 95 56 197 62 166 103 178 148 118 148 167 208 61 149 79 + 34 39 39 36 33 23 17 11 16 28 27 44 29 25 37 35 + 30 30 39 96 70 92 63 75 73 46 51 49 59 12 22 12 + 26 42 31 25 16 12 17 35 40 49 48 47 28 23 31 14 + 36 25 34 20 19 24 32 43 49 71 69 41 33 25 33 33 + 22 11 11 11 23 37 42 58 42 36 34 14 26 10 16 24 + 8 8 12 13 16 20 29 20 32 18 11 4 7 8 21 34 + 7 10 12 8 6 18 18 11 13 12 6 9 13 14 23 27 + 37 44 68 89 101 110 113 101 78 82 115 129 147 130 121 70 + 38 44 63 83 97 105 105 98 85 88 99 109 111 101 92 50 + 39 43 59 78 91 95 95 90 86 85 87 100 105 100 86 48 + 49 53 54 68 82 88 83 81 80 79 75 77 87 91 80 31 + 52 54 54 65 76 81 78 73 68 64 57 58 68 63 53 33 + 52 54 52 57 70 75 71 62 52 48 46 42 44 36 37 48 + 51 77 69 46 56 60 51 39 29 22 32 35 29 47 49 64 + 46 95 41 166 107 162 74 148 108 92 117 138 185 74 159 44 + 30 98 61 197 57 163 100 176 146 112 142 164 204 49 143 66 + 29 37 41 37 28 16 12 7 11 20 18 31 21 18 27 25 + 29 32 33 82 55 84 53 63 68 42 47 39 55 7 16 8 + 27 32 28 23 17 15 15 18 20 22 24 31 23 19 26 12 + 21 20 16 13 10 15 20 22 14 22 19 13 10 14 25 32 + 10 11 13 12 11 13 13 9 5 7 12 3 5 4 13 27 + 9 8 12 13 13 12 11 6 5 6 3 0 1 6 16 29 + 7 8 7 6 9 9 6 4 5 6 5 8 8 10 17 26 + +165 124 111 125 184 197 192 174 152 82 36 49 78 61 86 75 +185 157 176 190 198 196 187 211 187 84 52 75 88 45 53 47 +192 180 188 197 197 194 188 157 123 59 27 45 66 34 21 27 +195 189 195 194 192 187 171 218 217 60 78 54 103 100 27 20 +195 191 191 185 179 172 164 188 180 88 87 98 106 43 14 15 +187 182 182 181 173 166 155 163 169 57 71 80 112 61 25 13 +173 175 179 182 173 162 121 136 148 64 69 112 129 59 36 31 +177 176 177 176 172 159 125 142 166 41 99 100 115 86 73 35 +186 183 179 174 170 163 138 177 185 36 107 78 87 112 49 35 +190 186 179 172 169 166 148 141 137 50 86 40 71 77 57 40 +189 183 177 171 167 164 150 201 187 64 119 32 59 74 42 39 +183 178 174 166 162 156 141 161 104 81 110 44 52 54 42 16 +175 169 165 157 153 143 127 194 210 73 134 62 55 36 30 20 +161 155 151 144 144 140 146 81 80 72 77 67 74 32 25 31 +136 137 137 145 146 144 155 153 118 72 60 92 63 30 22 24 +128 132 131 145 145 143 139 124 56 64 58 56 81 49 22 18 +117 51 47 42 109 125 120 75 78 35 12 15 33 24 35 28 +161 103 117 133 132 112 93 169 146 38 22 32 33 17 22 22 +175 131 143 161 135 110 116 86 60 25 12 23 25 10 9 15 +185 152 163 155 134 117 75 193 203 29 61 28 33 26 8 12 +184 164 155 134 107 88 75 146 162 45 50 47 42 14 4 9 +168 150 141 127 100 85 69 122 147 27 53 50 69 33 11 7 +131 138 135 128 105 85 43 100 117 29 46 51 71 37 17 12 +133 139 135 125 107 86 49 118 150 16 74 40 49 43 32 14 +158 153 142 126 111 93 60 151 175 11 78 36 43 59 20 12 +169 160 145 126 114 101 74 90 108 17 65 17 32 44 29 18 +166 154 143 129 117 105 83 171 164 23 92 12 25 37 20 19 +155 145 136 121 110 99 77 117 61 34 72 16 20 23 17 6 +139 127 115 101 93 81 64 174 203 37 100 26 21 12 13 8 +110 98 88 77 77 73 87 44 58 39 39 32 33 11 12 12 + 73 70 65 74 74 74 97 108 101 39 30 43 25 12 9 10 + 61 64 60 70 71 70 68 58 28 35 30 27 37 22 9 8 + 69 49 47 30 33 49 65 44 65 25 8 13 33 28 30 26 +120 92 87 80 52 38 49 160 140 27 16 27 25 15 17 17 +130 101 100 91 62 36 48 72 48 18 7 20 15 4 6 10 +147 112 105 88 68 44 31 187 199 20 56 24 10 5 2 8 +130 109 100 77 59 42 36 135 158 32 40 31 14 3 1 8 +116 99 87 75 57 46 32 115 142 19 48 24 19 13 3 5 + 83 88 85 80 64 48 22 93 111 21 42 22 23 7 6 7 + 78 86 86 81 69 52 29 113 147 12 69 20 14 5 5 5 +101 98 91 82 74 62 39 147 173 7 66 19 22 10 6 4 +113 106 95 84 78 71 51 79 105 12 55 16 20 13 12 7 +110 105 95 89 81 75 61 163 160 16 85 15 15 13 12 10 +102 97 91 83 76 71 56 104 56 28 58 18 10 11 13 9 + 90 83 78 69 66 57 46 172 203 37 86 23 13 13 13 7 + 69 64 59 55 54 53 71 42 62 42 33 28 17 13 12 8 + 45 45 43 54 55 55 81 101 103 37 33 33 21 12 8 8 + 37 39 39 50 52 52 52 46 30 29 29 27 22 11 9 8 + + 75 47 27 20 15 13 31 35 35 40 39 16 20 31 24 18 + 86 53 21 27 14 25 36 73 49 57 42 42 30 25 22 22 + 61 45 34 100 43 61 59 86 112 77 74 54 36 32 30 49 + 78 88 66 103 106 112 129 115 87 71 59 52 55 74 63 81 + 49 75 45 54 98 80 112 100 78 40 32 44 62 67 92 56 + 36 52 27 78 87 71 69 99 107 86 119 110 134 77 60 58 + 82 84 59 60 88 57 64 41 36 50 64 81 73 72 72 64 +152 187 123 217 180 169 148 166 185 137 187 104 210 80 118 56 +174 211 157 218 188 163 136 142 177 141 201 161 194 81 153 124 +192 187 188 171 164 155 121 125 138 148 150 141 127 146 155 139 +197 196 194 187 172 166 162 159 163 166 164 156 143 140 144 143 +184 198 197 192 179 173 173 172 170 169 167 162 153 144 146 145 +125 190 197 194 185 181 182 176 174 172 171 166 157 144 145 145 +111 176 188 195 191 182 179 177 179 179 177 174 165 151 137 131 +124 157 180 189 191 182 175 176 183 186 183 178 169 155 137 132 +165 185 192 195 195 187 173 177 186 190 189 183 175 161 136 128 + 28 22 15 12 9 7 12 14 12 18 19 6 8 12 10 8 + 35 22 9 8 4 11 17 32 20 29 20 17 13 12 9 9 + 24 17 10 26 14 33 37 43 59 44 37 23 12 11 12 22 + 33 33 25 33 42 69 71 49 43 32 25 20 21 33 25 37 + 15 32 23 28 47 50 51 40 36 17 12 16 26 32 43 27 + 12 22 12 61 50 53 46 74 78 65 92 72 100 39 30 30 + 35 38 25 29 45 27 29 16 11 17 23 34 37 39 39 35 + 78 146 60 203 162 147 117 150 175 108 164 61 203 58 101 28 + 75 169 86 193 146 122 100 118 151 90 171 117 174 44 108 58 +120 93 116 75 75 69 43 49 60 74 83 77 64 87 97 68 +125 112 110 117 88 85 85 86 93 101 105 99 81 73 74 70 +109 132 135 134 107 100 105 107 111 114 117 110 93 77 74 71 + 42 133 161 155 134 127 128 125 126 126 129 121 101 77 74 70 + 47 117 143 163 155 141 135 135 142 145 143 136 115 88 65 60 + 51 103 131 152 164 150 138 139 153 160 154 145 127 98 70 64 +117 161 175 185 184 168 131 133 158 169 166 155 139 110 73 61 + 26 17 10 8 8 5 7 5 4 7 10 9 7 8 8 8 + 30 17 6 2 1 3 6 5 6 12 12 13 13 12 8 9 + 28 15 4 5 3 13 7 5 10 13 13 11 13 13 12 11 + 33 25 15 10 14 19 23 14 22 20 15 10 13 17 21 22 + 13 27 20 24 31 24 22 20 19 16 15 18 23 28 33 27 + 8 16 7 56 40 48 42 69 66 55 85 58 86 33 33 29 + 25 27 18 20 32 19 21 12 7 12 16 28 37 42 37 29 + 65 140 48 199 158 142 111 147 173 105 160 56 203 62 103 30 + 44 160 72 187 135 115 93 113 147 79 163 104 172 42 101 46 + 65 49 48 31 36 32 22 29 39 51 61 56 46 71 81 52 + 49 38 36 44 42 46 48 52 62 71 75 71 57 53 55 52 + 33 52 62 68 59 57 64 69 74 78 81 76 66 54 55 52 + 30 80 91 88 77 75 80 81 82 84 89 83 69 55 54 50 + 47 87 100 105 100 87 85 86 91 95 95 91 78 59 43 39 + 49 92 101 112 109 99 88 86 98 106 105 97 83 64 45 39 + 69 120 130 147 130 116 83 78 101 113 110 102 90 69 45 37 + + 18 22 49 81 56 58 64 56 124 139 143 145 145 131 132 128 + 24 22 30 63 92 60 72 118 153 155 144 146 145 137 137 136 + 31 25 32 74 67 77 72 80 81 146 140 144 144 151 155 161 + 20 30 36 55 62 134 73 210 194 127 143 153 157 165 169 175 + 16 42 54 52 44 110 81 104 161 141 156 162 166 174 178 183 + 39 42 74 59 32 119 64 187 201 150 164 167 171 177 183 189 + 40 57 77 71 40 86 50 137 141 148 166 169 172 179 186 190 + 35 49 112 87 78 107 36 185 177 138 163 170 174 179 183 186 + 35 73 86 115 100 99 41 166 142 125 159 172 176 177 176 177 + 31 36 59 129 112 69 64 148 136 121 162 173 182 179 175 173 + 13 25 61 112 80 71 57 169 163 155 166 173 181 182 182 187 + 15 14 43 106 98 87 88 180 188 164 172 179 185 191 191 195 + 20 27 100 103 54 78 60 217 218 171 187 192 194 195 189 195 + 27 21 34 66 45 27 59 123 157 188 194 197 197 188 180 192 + 47 53 45 88 75 52 84 187 211 187 196 198 190 176 157 185 + 75 86 61 78 49 36 82 152 174 192 197 184 125 111 124 165 + 8 9 22 37 27 30 35 28 58 68 70 71 70 60 64 61 + 10 9 12 25 43 30 39 101 108 97 74 74 74 65 70 73 + 12 12 11 33 32 39 39 58 44 87 73 77 77 88 98 110 + 8 13 12 21 26 100 37 203 174 64 81 93 101 115 127 139 + 6 17 23 20 16 72 34 61 117 77 99 110 121 136 145 155 + 19 20 37 25 12 92 23 164 171 83 105 117 129 143 154 166 + 18 29 44 32 17 65 17 108 90 74 101 114 126 145 160 169 + 12 20 59 43 36 78 11 175 151 60 93 111 126 142 153 158 + 14 32 43 49 40 74 16 150 118 49 86 107 125 135 139 133 + 12 17 37 71 51 46 29 117 100 43 85 105 128 135 138 131 + 7 11 33 69 50 53 27 147 122 69 85 100 127 141 150 168 + 9 4 14 42 47 50 45 162 146 75 88 107 134 155 164 184 + 12 8 26 33 28 61 29 203 193 75 117 134 155 163 152 185 + 15 9 10 25 23 12 25 60 86 116 110 135 161 143 131 175 + 22 22 17 33 32 22 38 146 169 93 112 132 133 117 103 161 + 28 35 24 33 15 12 35 78 75 120 125 109 42 47 51 117 + 8 9 11 22 27 29 29 30 46 52 52 52 50 39 39 37 + 8 8 12 21 33 33 37 103 101 81 55 55 54 43 45 45 + 8 12 13 17 28 33 42 62 42 71 53 54 55 59 64 69 + 7 13 13 13 23 86 37 203 172 46 57 66 69 78 83 90 + 9 13 11 10 18 58 28 56 104 56 71 76 83 91 97 102 + 10 12 13 15 15 85 16 160 163 61 75 81 89 95 105 110 + 7 12 13 20 16 55 12 105 79 51 71 78 84 95 106 113 + 4 6 10 22 19 66 7 173 147 39 62 74 82 91 98 101 + 5 5 5 14 20 69 12 147 113 29 52 69 81 86 86 78 + 7 6 7 23 22 42 21 111 93 22 48 64 80 85 88 83 + 5 3 13 19 24 48 19 142 115 32 46 57 75 87 99 116 + 8 1 3 14 31 40 32 158 135 36 42 59 77 100 109 130 + 8 2 5 10 24 56 20 199 187 31 44 68 88 105 112 147 + 10 6 4 15 20 7 18 48 72 48 36 62 91 100 101 130 + 17 17 15 25 27 16 27 140 160 49 38 52 80 87 92 120 + 26 30 28 33 13 8 25 65 44 65 49 33 30 47 49 69 diff --git a/AR/marker/pattern-treasure.png b/AR/marker/pattern-treasure.png new file mode 100644 index 000000000..14352f5e2 Binary files /dev/null and b/AR/marker/pattern-treasure.png differ diff --git a/AR/marker/seven320.patt b/AR/marker/seven320.patt new file mode 100644 index 000000000..ee8b0bc50 --- /dev/null +++ b/AR/marker/seven320.patt @@ -0,0 +1,195 @@ +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 246 219 217 215 243 230 249 249 235 239 215 217 220 245 255 +255 219 122 118 131 200 118 173 193 163 180 131 116 130 214 255 +255 217 118 82 158 186 88 96 89 150 172 159 78 129 211 255 +255 216 132 156 159 181 121 61 39 63 155 159 155 143 209 255 +255 240 189 179 189 218 205 150 137 199 217 185 186 200 241 255 +255 228 138 56 144 136 27 153 100 92 77 95 153 183 232 255 +255 226 136 97 59 190 74 149 114 99 75 128 138 179 238 255 +255 228 143 87 96 99 133 104 106 165 95 90 122 172 235 255 +255 217 152 114 57 105 140 142 68 80 82 120 144 162 219 255 +255 235 178 159 145 206 104 141 146 88 172 174 157 142 207 255 +255 216 133 161 161 190 66 10 103 96 155 155 93 202 241 255 +255 217 117 78 156 179 81 77 128 80 9 105 120 152 221 255 +255 220 130 129 142 190 134 211 127 143 77 154 140 136 224 255 +255 245 214 211 209 238 228 252 230 234 218 243 231 215 245 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 246 219 217 215 243 230 249 249 235 239 215 217 220 245 255 +255 219 122 118 131 200 118 173 193 163 180 131 116 130 214 255 +255 217 118 82 158 186 88 96 89 150 172 159 78 129 211 255 +255 216 132 156 159 181 121 61 39 63 155 159 155 143 209 255 +255 240 189 179 189 218 205 150 137 199 217 185 186 200 241 255 +255 228 138 56 144 136 27 153 100 92 77 95 153 183 232 255 +255 226 136 97 59 190 74 149 114 99 75 128 138 179 238 255 +255 228 143 87 96 99 133 104 106 165 95 90 122 172 235 255 +255 217 152 114 57 105 140 142 68 80 82 120 144 162 219 255 +255 235 178 159 145 206 104 141 146 88 172 174 157 142 207 255 +255 216 133 161 161 190 66 10 103 96 155 155 93 202 241 255 +255 217 117 78 156 179 81 77 128 80 9 105 120 152 221 255 +255 220 130 129 142 190 134 211 127 143 77 154 140 136 224 255 +255 245 214 211 209 238 228 252 230 234 218 243 231 215 245 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 246 219 217 215 243 230 249 249 235 239 215 217 220 245 255 +255 219 122 118 131 200 118 173 193 163 180 131 116 130 214 255 +255 217 118 82 158 186 88 96 89 150 172 159 78 129 211 255 +255 216 132 156 159 181 121 61 39 63 155 159 155 143 209 255 +255 240 189 179 189 218 205 150 137 199 217 185 186 200 241 255 +255 228 138 56 144 136 27 153 100 92 77 95 153 183 232 255 +255 226 136 97 59 190 74 149 114 99 75 128 138 179 238 255 +255 228 143 87 96 99 133 104 106 165 95 90 122 172 235 255 +255 217 152 114 57 105 140 142 68 80 82 120 144 162 219 255 +255 235 178 159 145 206 104 141 146 88 172 174 157 142 207 255 +255 216 133 161 161 190 66 10 103 96 155 155 93 202 241 255 +255 217 117 78 156 179 81 77 128 80 9 105 120 152 221 255 +255 220 130 129 142 190 134 211 127 143 77 154 140 136 224 255 +255 245 214 211 209 238 228 252 230 234 218 243 231 215 245 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 + +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 245 218 216 214 243 236 239 238 222 213 242 225 227 247 255 +255 217 131 128 142 201 184 178 176 159 140 201 152 137 220 255 +255 213 119 79 161 186 156 136 126 146 159 99 121 141 233 255 +255 211 133 155 159 182 101 123 95 120 176 150 105 158 245 255 +255 237 181 174 157 213 74 79 89 84 179 152 8 79 222 255 +255 232 161 152 61 196 94 103 168 79 87 93 78 149 238 255 +255 249 192 89 40 140 94 120 100 69 149 110 129 127 232 255 +255 249 169 94 58 147 153 151 98 145 141 12 81 212 253 255 +255 229 118 91 121 200 32 81 132 143 104 65 83 140 232 255 +255 242 197 183 180 215 134 186 96 110 206 187 176 189 240 255 +255 211 135 162 160 189 146 59 101 54 149 162 162 142 214 255 +255 213 118 78 160 175 55 96 83 112 159 156 79 127 216 255 +255 215 124 119 135 188 136 138 141 157 179 134 119 131 218 255 +255 244 215 213 211 239 225 223 224 213 234 211 213 217 245 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 245 218 216 214 243 236 239 238 222 213 242 225 227 247 255 +255 217 131 128 142 201 184 178 176 159 140 201 152 137 220 255 +255 213 119 79 161 186 156 136 126 146 159 99 121 141 233 255 +255 211 133 155 159 182 101 123 95 120 176 150 105 158 245 255 +255 237 181 174 157 213 74 79 89 84 179 152 8 79 222 255 +255 232 161 152 61 196 94 103 168 79 87 93 78 149 238 255 +255 249 192 89 40 140 94 120 100 69 149 110 129 127 232 255 +255 249 169 94 58 147 153 151 98 145 141 12 81 212 253 255 +255 229 118 91 121 200 32 81 132 143 104 65 83 140 232 255 +255 242 197 183 180 215 134 186 96 110 206 187 176 189 240 255 +255 211 135 162 160 189 146 59 101 54 149 162 162 142 214 255 +255 213 118 78 160 175 55 96 83 112 159 156 79 127 216 255 +255 215 124 119 135 188 136 138 141 157 179 134 119 131 218 255 +255 244 215 213 211 239 225 223 224 213 234 211 213 217 245 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 245 218 216 214 243 236 239 238 222 213 242 225 227 247 255 +255 217 131 128 142 201 184 178 176 159 140 201 152 137 220 255 +255 213 119 79 161 186 156 136 126 146 159 99 121 141 233 255 +255 211 133 155 159 182 101 123 95 120 176 150 105 158 245 255 +255 237 181 174 157 213 74 79 89 84 179 152 8 79 222 255 +255 232 161 152 61 196 94 103 168 79 87 93 78 149 238 255 +255 249 192 89 40 140 94 120 100 69 149 110 129 127 232 255 +255 249 169 94 58 147 153 151 98 145 141 12 81 212 253 255 +255 229 118 91 121 200 32 81 132 143 104 65 83 140 232 255 +255 242 197 183 180 215 134 186 96 110 206 187 176 189 240 255 +255 211 135 162 160 189 146 59 101 54 149 162 162 142 214 255 +255 213 118 78 160 175 55 96 83 112 159 156 79 127 216 255 +255 215 124 119 135 188 136 138 141 157 179 134 119 131 218 255 +255 244 215 213 211 239 225 223 224 213 234 211 213 217 245 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 + +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 247 220 233 245 222 238 232 253 232 240 214 216 218 245 255 +255 227 137 141 158 79 149 127 212 140 189 142 127 131 217 255 +255 225 152 121 105 8 78 129 81 83 176 162 79 119 213 255 +255 242 201 99 150 152 93 110 12 65 187 162 156 134 211 255 +255 213 140 159 176 179 87 149 141 104 206 149 159 179 234 255 +255 222 159 146 120 84 79 69 145 143 110 54 112 157 213 255 +255 238 176 126 95 89 168 100 98 132 96 101 83 141 224 255 +255 239 178 136 123 79 103 120 151 81 186 59 96 138 223 255 +255 236 184 156 101 74 94 94 153 32 134 146 55 136 225 255 +255 243 201 186 182 213 196 140 147 200 215 189 175 188 239 255 +255 214 142 161 159 157 61 40 58 121 180 160 160 135 211 255 +255 216 128 79 155 174 152 89 94 91 183 162 78 119 213 255 +255 218 131 119 133 181 161 192 169 118 197 135 118 124 215 255 +255 245 217 213 211 237 232 249 249 229 242 211 213 215 244 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 247 220 233 245 222 238 232 253 232 240 214 216 218 245 255 +255 227 137 141 158 79 149 127 212 140 189 142 127 131 217 255 +255 225 152 121 105 8 78 129 81 83 176 162 79 119 213 255 +255 242 201 99 150 152 93 110 12 65 187 162 156 134 211 255 +255 213 140 159 176 179 87 149 141 104 206 149 159 179 234 255 +255 222 159 146 120 84 79 69 145 143 110 54 112 157 213 255 +255 238 176 126 95 89 168 100 98 132 96 101 83 141 224 255 +255 239 178 136 123 79 103 120 151 81 186 59 96 138 223 255 +255 236 184 156 101 74 94 94 153 32 134 146 55 136 225 255 +255 243 201 186 182 213 196 140 147 200 215 189 175 188 239 255 +255 214 142 161 159 157 61 40 58 121 180 160 160 135 211 255 +255 216 128 79 155 174 152 89 94 91 183 162 78 119 213 255 +255 218 131 119 133 181 161 192 169 118 197 135 118 124 215 255 +255 245 217 213 211 237 232 249 249 229 242 211 213 215 244 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 247 220 233 245 222 238 232 253 232 240 214 216 218 245 255 +255 227 137 141 158 79 149 127 212 140 189 142 127 131 217 255 +255 225 152 121 105 8 78 129 81 83 176 162 79 119 213 255 +255 242 201 99 150 152 93 110 12 65 187 162 156 134 211 255 +255 213 140 159 176 179 87 149 141 104 206 149 159 179 234 255 +255 222 159 146 120 84 79 69 145 143 110 54 112 157 213 255 +255 238 176 126 95 89 168 100 98 132 96 101 83 141 224 255 +255 239 178 136 123 79 103 120 151 81 186 59 96 138 223 255 +255 236 184 156 101 74 94 94 153 32 134 146 55 136 225 255 +255 243 201 186 182 213 196 140 147 200 215 189 175 188 239 255 +255 214 142 161 159 157 61 40 58 121 180 160 160 135 211 255 +255 216 128 79 155 174 152 89 94 91 183 162 78 119 213 255 +255 218 131 119 133 181 161 192 169 118 197 135 118 124 215 255 +255 245 217 213 211 237 232 249 249 229 242 211 213 215 244 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 + +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 245 217 213 211 234 213 224 223 225 239 211 213 215 244 255 +255 218 131 119 134 179 157 141 138 136 188 135 119 124 215 255 +255 216 127 79 156 159 112 83 96 55 175 160 78 118 213 255 +255 214 142 162 162 149 54 101 59 146 189 160 162 135 211 255 +255 240 189 176 187 206 110 96 186 134 215 180 183 197 242 255 +255 232 140 83 65 104 143 132 81 32 200 121 91 118 229 255 +255 253 212 81 12 141 145 98 151 153 147 58 94 169 249 255 +255 232 127 129 110 149 69 100 120 94 140 40 89 192 249 255 +255 238 149 78 93 87 79 168 103 94 196 61 152 161 232 255 +255 222 79 8 152 179 84 89 79 74 213 157 174 181 237 255 +255 245 158 105 150 176 120 95 123 101 182 159 155 133 211 255 +255 233 141 121 99 159 146 126 136 156 186 161 79 119 213 255 +255 220 137 152 201 140 159 176 178 184 201 142 128 131 217 255 +255 247 227 225 242 213 222 238 239 236 243 214 216 218 245 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 245 217 213 211 234 213 224 223 225 239 211 213 215 244 255 +255 218 131 119 134 179 157 141 138 136 188 135 119 124 215 255 +255 216 127 79 156 159 112 83 96 55 175 160 78 118 213 255 +255 214 142 162 162 149 54 101 59 146 189 160 162 135 211 255 +255 240 189 176 187 206 110 96 186 134 215 180 183 197 242 255 +255 232 140 83 65 104 143 132 81 32 200 121 91 118 229 255 +255 253 212 81 12 141 145 98 151 153 147 58 94 169 249 255 +255 232 127 129 110 149 69 100 120 94 140 40 89 192 249 255 +255 238 149 78 93 87 79 168 103 94 196 61 152 161 232 255 +255 222 79 8 152 179 84 89 79 74 213 157 174 181 237 255 +255 245 158 105 150 176 120 95 123 101 182 159 155 133 211 255 +255 233 141 121 99 159 146 126 136 156 186 161 79 119 213 255 +255 220 137 152 201 140 159 176 178 184 201 142 128 131 217 255 +255 247 227 225 242 213 222 238 239 236 243 214 216 218 245 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 245 217 213 211 234 213 224 223 225 239 211 213 215 244 255 +255 218 131 119 134 179 157 141 138 136 188 135 119 124 215 255 +255 216 127 79 156 159 112 83 96 55 175 160 78 118 213 255 +255 214 142 162 162 149 54 101 59 146 189 160 162 135 211 255 +255 240 189 176 187 206 110 96 186 134 215 180 183 197 242 255 +255 232 140 83 65 104 143 132 81 32 200 121 91 118 229 255 +255 253 212 81 12 141 145 98 151 153 147 58 94 169 249 255 +255 232 127 129 110 149 69 100 120 94 140 40 89 192 249 255 +255 238 149 78 93 87 79 168 103 94 196 61 152 161 232 255 +255 222 79 8 152 179 84 89 79 74 213 157 174 181 237 255 +255 245 158 105 150 176 120 95 123 101 182 159 155 133 211 255 +255 233 141 121 99 159 146 126 136 156 186 161 79 119 213 255 +255 220 137 152 201 140 159 176 178 184 201 142 128 131 217 255 +255 247 227 225 242 213 222 238 239 236 243 214 216 218 245 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 diff --git a/AR/marker/seven320.png b/AR/marker/seven320.png new file mode 100644 index 000000000..bae9926ac Binary files /dev/null and b/AR/marker/seven320.png differ diff --git a/AR/profile.html b/AR/profile.html new file mode 100644 index 000000000..9dc790823 --- /dev/null +++ b/AR/profile.html @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AR/profile.js b/AR/profile.js new file mode 100644 index 000000000..75fab1791 --- /dev/null +++ b/AR/profile.js @@ -0,0 +1,27 @@ +let datas = window.location.search +let words = datas.split("---") + +const username = words[0].split("=")[1] +const belong = words[1] +const tel = words[2] +const email = words[3] +const twitterID = words[4] +const githubID = words[5] + +console.log("success load page") +console.log(username,belong,tel,email,twitterID,githubID) + +let boxname = document.querySelector(`#name`) +boxname.setAttribute("value", "NAME:" + username) + +let formbox = document.querySelector(`#other`) + +let form_text = `belong:${belong}\nTEL:${tel}\ne-mail:${email}` +if(twitterID.length > 3){ + form_text += `\nTwitter:${twitterID}` +} +if(githubID.length > 0){ + form_text += `\ngithub:${githubID}` +} + +formbox.setAttribute("value", form_text) \ No newline at end of file diff --git a/AR/server/secret.json b/AR/server/secret.json new file mode 100644 index 000000000..643307204 --- /dev/null +++ b/AR/server/secret.json @@ -0,0 +1,6 @@ +{ + "consumer_key" :"cXeXwTgOlx8jsSIpygQDpT6JI", + "consumer_secret" :"j8hF0NnMfPhcU8JjSHnCsQUnTzkkIFZvRKtsYYTaPirKTTUw9h", + "access_token_key" :"1145375891356151809-SYBtZOPgIGby3FXOw2p9eqr6Fw8Tid", + "access_token_secret" :"kJ1d7qsjVVnblKERQYS4k9N68eoYZGmafl5jHVZg0HHkn" +} diff --git a/AR/server/server.js b/AR/server/server.js new file mode 100644 index 000000000..a8af774f3 --- /dev/null +++ b/AR/server/server.js @@ -0,0 +1,101 @@ +var express = require('express'); +const fetch = require('node-fetch'); +const csp = require('express-csp-header'); +const router = require('express-promise-router')(); +const { createCanvas, Image } = require('canvas'); +const QRCode = require('qrcode'); +const twitter = require('twitter') +const fs = require('fs') + +var app = express(); + + +app.use(function(req, res, next){ + res.header("Access-Control-Allow-Origin", "*"); + res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); + next() +}); + +app.use(csp({ + 'img-src':['data:','images.com'] +})) + +app.get('/test', function(req, res){ + console.log("3000") + res.send("3000 is fine") +}) + +app.get('/qr/:query', async function(req, res){ // get QR code + + let requesturl = req.params.query + // console.log("request url is ",requesturl) + + // let requesturl = `https://api.qrserver.com/v1/create-qr-code/?data=https://google.com&size=200x200` + // const response = await fetch(requesturl) + // let buf = await response.buffer() + // let base64 = buf.toString('base64') + // res.send(base64) + + let result = await makeQRcode(requesturl) + res.send(result) +}); + +app.get('/profile/', async function(req, res){ + console.log(req.params.name) + + let url = require(req.params.name) + console.log("profile server") + +}) + +app.listen(3000, function(){ + console.log('Example app listening on port!') +}) + +function Test(){ + console.log("test") +} + + +// QRコード生成 +async function makeQRcode(url){ + console.log("in functions") + return new Promise(function(resolve, reject){ + + // canvas準備 + let canvas_size = 400 + const canvas = createCanvas(canvas_size, canvas_size) + + // QRコードの設定準備 + const segment = [ + { data:"AR名刺\n", mode:"kanji"}, + { data:url, mode:"byte"} //alphanumericだと怒られる + ]; + const options = { + width:1000, + errorCorrectionLevel: 'H' + }; + + QRCode.toCanvas(canvas, segment, options, (error) => { + let icon = new Image(); + + icon.onload = ()=>{ + const left = Math.floor((canvas.width - icon.width) / 2); // x + const top = Math.floor((canvas.height - icon.height) / 2); // y + + // 画像を載せる + const ctx = canvas.getContext('2d'); + + ctx.drawImage(icon, left, top); + + // 出力 + resolve(canvas.toDataURL()) + }; + icon.src = './QRlogo/pattern-treasure_100.png'; // 上に載せる画像 + }); + resolve(`${canvas.toDataURL()}`) + }) +} + + +function \ No newline at end of file diff --git a/AR/server/token.js b/AR/server/token.js new file mode 100644 index 000000000..d42b02bc4 --- /dev/null +++ b/AR/server/token.js @@ -0,0 +1,19 @@ +// const twittertoken = "hoge" + + + +// const client = new Twitter({ +// cosumer_key:"cXeXwTgOlx8jsSIpygQDpT6JI", +// consumer_secret:"j8hF0NnMfPhcU8JjSHnCsQUnTzkkIFZvRKtsYYTaPirKTTUw9h", +// access_toke_key:"1145375891356151809-SYBtZOPgIGby3FXOw2p9eqr6Fw8Tid", +// access_token_secret:"kJ1d7qsjVVnblKERQYS4k9N68eoYZGmafl5jHVZg0HHkn" +// }) + +exports.twitter = client + +const Twitter = require('twitter') + +var credentials = require("./secret.json"); + + + diff --git a/AR/server/token.mjs b/AR/server/token.mjs new file mode 100644 index 000000000..96d8167e0 --- /dev/null +++ b/AR/server/token.mjs @@ -0,0 +1,11 @@ +const twittertoken = "hoge" + +export{twittertoken} + + +// { +// "cosumer_key":"cXeXwTgOlx8jsSIpygQDpT6JI", +// "consumer_secret":"j8hF0NnMfPhcU8JjSHnCsQUnTzkkIFZvRKtsYYTaPirKTTUw9h", +// "access_toke_key":"1145375891356151809-SYBtZOPgIGby3FXOw2p9eqr6Fw8Tid", +// "access_token_secret":"kJ1d7qsjVVnblKERQYS4k9N68eoYZGmafl5jHVZg0HHkn" +// } diff --git a/backend/README.md b/backend/README.md index 8fd027a04..9bbd12924 100644 --- a/backend/README.md +++ b/backend/README.md @@ -1,12 +1,20 @@ +# Slide + +https://go-talks.appspot.com/github.com/voyagegroup/talks/2019/treasure-go-day2/intro.slide#1 + # Getting Started ## 1. Database 立ち上げ `../database` に構成などが定義されているので、読んでみてください。 +以下のターゲットを叩くと、databaseの準備をします。 + ```console ❯ make -f integration.mk database-init -make -C ../database init +``` + +```console which goose || GO111MODULE=off go get -u github.com/pressly/goose/cmd/goose /Users/j-chikamori/go/bin/goose docker-compose up -d @@ -72,9 +80,14 @@ PORT=1991 使っているAPI: [Exchange custom token for an ID and refresh token](https://firebase.google.com/docs/reference/rest/auth/#section-refresh-token) それぞれのキーについては、上記リンクを見れば大体分かる。 +トークンの作成 + ```console ❯ make -f integration.mk create-token UID=demo go run ./cmd/customtoken/main.go demo .idToken +``` + +```console { "kind": "identitytoolkit#VerifyCustomTokenResponse", "idToken": "idtoken", @@ -88,17 +101,27 @@ go run ./cmd/customtoken/main.go demo .idToken ## 5. Hello World +*サーバー立ち上げ* + ```console ❯ make run go run cmd/api/main.go +``` + +```console 2019/08/08 11:32:47 server.go:51: Listening on port 1991 ``` サーバーを立ち上げた状態で、別シェルから以下を叩く。 +*認証ありエンドポイントへのリクエスト* + ```console ❯ make -f integration.mk req-private curl -v -H "Authorization: Bearer Hoge" localhost:1991/private +``` + +```console * Trying ::1... * TCP_NODELAY set * Connected to localhost (::1) port 1991 (#0) @@ -116,10 +139,16 @@ curl -v -H "Authorization: Bearer Hoge" localhost:1991/private < * Connection #0 to host localhost left intact {"message":"Hello from private endpoint! Your firebase uuid is demo"} +``` +*認証なしエンドポイントへのリクエスト* +```console ❯ make -f integration.mk req-public curl -v localhost:1991/public +``` + +```console * Trying ::1... * TCP_NODELAY set * Connected to localhost (::1) port 1991 (#0) @@ -149,16 +178,29 @@ curl -v localhost:1991/public コードを書き換える度に `go run` し直すのは面倒くさいので、書き換えるとrebuildしてくれるコマンドを用意しているので活用してください。 +realizeをgo getする + ```console ❯ make dev-deps GO111MODULE=off go get -u -v \ github.com/oxequa/realize +``` + +``` github.com/oxequa/realize (download) github.com/oxequa/interact (download) github.com/fatih/color (download) github.com/fsnotify/fsnotify (download) +``` + +realizeを使って実行する + +```console ❯ make refresh-run realize start +``` + +``` console [11:36:48][BACKEND] : Watching 21 file/s 14 folder/s [11:36:48][BACKEND] : Install started [11:36:51][BACKEND] : Install completed in 3.653 s diff --git a/backend/controller/article.go b/backend/controller/article.go index 524ab3941..647e6b9e5 100644 --- a/backend/controller/article.go +++ b/backend/controller/article.go @@ -17,15 +17,15 @@ import ( ) type Article struct { - dbx *sqlx.DB + db *sqlx.DB } -func NewArticle(dbx *sqlx.DB) *Article { - return &Article{dbx: dbx} +func NewArticle(db *sqlx.DB) *Article { + return &Article{db: db} } func (a *Article) Index(w http.ResponseWriter, r *http.Request) (int, interface{}, error) { - articles, err := repository.AllArticle(a.dbx) + articles, err := repository.AllArticle(a.db) if err != nil { return http.StatusInternalServerError, nil, err } @@ -44,7 +44,7 @@ func (a *Article) Show(w http.ResponseWriter, r *http.Request) (int, interface{} return http.StatusBadRequest, nil, err } - article, err := repository.FindArticle(a.dbx, aid) + article, err := repository.FindArticle(a.db, aid) if err != nil && err == sql.ErrNoRows { return http.StatusNotFound, nil, err } else if err != nil { @@ -60,7 +60,7 @@ func (a *Article) Create(w http.ResponseWriter, r *http.Request) (int, interface return http.StatusBadRequest, nil, err } - articleService := service.NewArticleService(a.dbx) + articleService := service.NewArticle(a.db) id, err := articleService.Create(newArticle) if err != nil { return http.StatusInternalServerError, nil, err @@ -87,7 +87,7 @@ func (a *Article) Update(w http.ResponseWriter, r *http.Request) (int, interface return http.StatusBadRequest, nil, err } - articleService := service.NewArticleService(a.dbx) + articleService := service.NewArticle(a.db) err = articleService.Update(aid, reqArticle) if err != nil && errors.Cause(err) == sql.ErrNoRows { return http.StatusNotFound, nil, err @@ -110,7 +110,7 @@ func (a *Article) Destroy(w http.ResponseWriter, r *http.Request) (int, interfac return http.StatusBadRequest, nil, err } - articleService := service.NewArticleService(a.dbx) + articleService := service.NewArticle(a.db) err = articleService.Destroy(aid) if err != nil && errors.Cause(err) == sql.ErrNoRows { return http.StatusNotFound, nil, err diff --git a/backend/dbutil/tx.go b/backend/dbutil/tx.go index 99f025778..65947ca3f 100644 --- a/backend/dbutil/tx.go +++ b/backend/dbutil/tx.go @@ -11,8 +11,8 @@ import ( // TXHandler is handler for working with transaction. // This is wrapper function for commit and rollback. -func TXHandler(dbx *sqlx.DB, f func(*sqlx.Tx) error) error { - tx, err := dbx.Beginx() +func TXHandler(db *sqlx.DB, f func(*sqlx.Tx) error) error { + tx, err := db.Beginx() if err != nil { return errors.Wrap(err, "start transaction failed") } diff --git a/backend/go.mod b/backend/go.mod index eadca7bd1..662fdd0cc 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -13,7 +13,4 @@ require ( github.com/justinas/alice v0.0.0-20171023064455-03f45bd4b7da github.com/pkg/errors v0.8.1 github.com/rs/cors v1.6.0 - go.uber.org/atomic v1.4.0 // indirect - go.uber.org/multierr v1.1.0 // indirect - go.uber.org/zap v1.10.0 ) diff --git a/backend/go.sum b/backend/go.sum index 849b55e7a..5af49b0ca 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -56,12 +56,6 @@ github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0 h1:C9hSCOW830chIVkdja34wa6Ky+IzWllkUinR+BtRZd4= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= -go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU= -go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= diff --git a/backend/middleware/auth.go b/backend/middleware/auth.go index 709b50094..29797230f 100644 --- a/backend/middleware/auth.go +++ b/backend/middleware/auth.go @@ -16,19 +16,19 @@ const ( bearer = "Bearer" ) -type AuthMiddleware struct { +type Auth struct { client *auth.Client db *sqlx.DB } -func NewAuthMiddleware(client *auth.Client, db *sqlx.DB) *AuthMiddleware { - return &AuthMiddleware{ +func NewAuth(client *auth.Client, db *sqlx.DB) *Auth { + return &Auth{ client: client, db: db, } } -func (auth *AuthMiddleware) Handler(next http.Handler) http.Handler { +func (auth *Auth) Handler(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { idToken, err := getTokenFromHeader(r) if err != nil { diff --git a/backend/repository/user.go b/backend/repository/user.go index 3811a4364..549447173 100644 --- a/backend/repository/user.go +++ b/backend/repository/user.go @@ -10,7 +10,7 @@ import ( func GetUser(db *sqlx.DB, uid string) (*model.User, error) { var u model.User if err := db.Get(&u, ` -select id, firebase_uid, display_name, email, photo_url from user where firebase_uid = ? limit 1 +SELECT id, firebase_uid, display_name, email, photo_url FROM user WHERE firebase_uid = ? LIMIT 1 `, uid); err != nil { return nil, err } diff --git a/backend/sample/private.go b/backend/sample/private.go index 0be296c5c..94abdfd21 100644 --- a/backend/sample/private.go +++ b/backend/sample/private.go @@ -12,12 +12,12 @@ import ( ) type PrivateHandler struct { - dbx *sqlx.DB + db *sqlx.DB } -func NewPrivateHandler(dbx *sqlx.DB) *PrivateHandler { +func NewPrivateHandler(db *sqlx.DB) *PrivateHandler { return &PrivateHandler{ - dbx: dbx, + db: db, } } @@ -28,7 +28,7 @@ func (h *PrivateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { WriteJSON(nil, w, http.StatusInternalServerError) return } - user, err := repository.GetUser(h.dbx, contextUser.FirebaseUID) + user, err := repository.GetUser(h.db, contextUser.FirebaseUID) if err != nil { log.Printf("Show user failed: %s", err) WriteJSON(nil, w, http.StatusInternalServerError) diff --git a/backend/server.go b/backend/server.go index 911ba9cde..da8594ec8 100644 --- a/backend/server.go +++ b/backend/server.go @@ -17,13 +17,13 @@ import ( "github.com/jmoiron/sqlx" "github.com/rs/cors" "github.com/voyagegroup/treasure-app/controller" - db2 "github.com/voyagegroup/treasure-app/db" + "github.com/voyagegroup/treasure-app/db" "github.com/voyagegroup/treasure-app/firebase" "github.com/voyagegroup/treasure-app/middleware" ) type Server struct { - dbx *sqlx.DB + db *sqlx.DB router *mux.Router authClient *auth.Client } @@ -39,12 +39,12 @@ func (s *Server) Init(datasource string) { } s.authClient = authClient - db := db2.NewDB(datasource) - dbx, err := db.Open() + cs := db.NewDB(datasource) + dbcon, err := cs.Open() if err != nil { log.Fatalf("failed db init. %s", err) } - s.dbx = dbx + s.db = dbcon s.router = s.Route() } @@ -60,10 +60,18 @@ func (s *Server) Run(addr string) { } func (s *Server) Route() *mux.Router { - authMiddleware := middleware.NewAuthMiddleware(s.authClient, s.dbx) + authMiddleware := middleware.NewAuth(s.authClient, s.db) corsMiddleware := cors.New(cors.Options{ AllowedOrigins: []string{"*"}, AllowedHeaders: []string{"Authorization"}, + AllowedMethods: []string{ + http.MethodHead, + http.MethodGet, + http.MethodPost, + http.MethodPut, + http.MethodPatch, + http.MethodDelete, + }, }) commonChain := alice.New( @@ -77,9 +85,9 @@ func (s *Server) Route() *mux.Router { r := mux.NewRouter() r.Methods(http.MethodGet).Path("/public").Handler(commonChain.Then(sample.NewPublicHandler())) - r.Methods(http.MethodGet).Path("/private").Handler(authChain.Then(sample.NewPrivateHandler(s.dbx))) + r.Methods(http.MethodGet).Path("/private").Handler(authChain.Then(sample.NewPrivateHandler(s.db))) - articleController := controller.NewArticle(s.dbx) + articleController := controller.NewArticle(s.db) r.Methods(http.MethodPost).Path("/articles").Handler(authChain.Then(AppHandler{articleController.Create})) r.Methods(http.MethodPut).Path("/articles/{id}").Handler(authChain.Then(AppHandler{articleController.Update})) r.Methods(http.MethodDelete).Path("/articles/{id}").Handler(authChain.Then(AppHandler{articleController.Destroy})) diff --git a/backend/service/article.go b/backend/service/article.go index 2a3c58391..92b862d11 100644 --- a/backend/service/article.go +++ b/backend/service/article.go @@ -13,7 +13,7 @@ type Article struct { db *sqlx.DB } -func NewArticleService(db *sqlx.DB) *Article { +func NewArticle(db *sqlx.DB) *Article { return &Article{db} } diff --git a/frontend/README.md b/frontend/README.md new file mode 100644 index 000000000..f27c0834c --- /dev/null +++ b/frontend/README.md @@ -0,0 +1,36 @@ +# Getting Started + +## 1. 環境構築 + +**make setup** + +設定ファイルのコピーとパッケージのセットアップを行う + +```console +❯ make setup +``` + +**Firebase API Key** + +API講義で作ったFirebaseプロジェクトを使う + +1. [Firebase](https://firebase.google.com/) のプロジェクトページを開く +1. `Project Overview` の右にある `⚙(歯車)` ボタンを押して、 `プロジェクトの設定` へ遷移 +1. `Firebase SDK snippet` をコピーして、`.env` ファイルの `FIREBASE_...` に設定する + +``` +FIREBASE_APIKEY="REPLACE_ME" +FIREBASE_AUTHDOMAIN="REPLACE_ME" +FIREBASE_DATABASEURL="REPLACE_ME" +FIREBASE_PROJECTID="REPLACE_ME" +FIREBASE_MESSAGINGSENDERID="REPLACE_ME" +FIREBASE_APPID="REPLACE_ME" +``` + +## 2. Hello World + +**フロント立ち上げ** + +```console +❯ make dev +```